Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:49:09+00:00 2026-06-03T09:49:09+00:00

The below code calls the ReadXMLFile constructor ReadXMLFile r=new ReadXMLFile(small.xml); HashMap r=r.getrcset(); I am

  • 0

The below code calls the ReadXMLFile constructor

ReadXMLFile r=new ReadXMLFile("small.xml");
HashMap r=r.getrcset();

I am updating the sathiya hashmap using update fn which will be called by the ReadXMLFile constructor. Its working fine ie.( elements are getting added to sathiya hashmap) inside update because i can print it . but the sathiya hashmap is empty in the getrcset file. while i try to print it i get 0: {} 1:{} . cant figure y its empty

package iws.falcon.matcher.pbm;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.HashMap;
import java.util.Iterator;
import java.util.*; 

public class ReadXMLFile {

public HashMap sathiya = new HashMap();
String filepath=null;
int cid=0;
int f=0;
HashMap rc=null;

public HashMap getrcset()
{
System.out.println("inside getsathiya"+sathiya.size());
Set set = sathiya.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
}
System.out.println("god"+sathiya);
return sathiya;
}

public void update(HashMap god)
{
sathiya.put(cid,god);
for (int i=0,n=sathiya.size();i<n;i++)
System.out.println("inside update fn"+sathiya.get(i));
cid++;
}

   public ReadXMLFile (String fp) 
    {
    filepath=fp;
     try {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    DefaultHandler handler = new DefaultHandler() {
    boolean name = false;
    boolean cluster=false;

    public void startElement(String uri, String localName,String qName, 
                Attributes attributes) throws SAXException {

        if (qName.equalsIgnoreCase("CLUSTER")) 
        {rc=new HashMap();

        }`enter code here`

        if (qName.equalsIgnoreCase("URI")) {
            name = true;
        }

    }

    public void endElement(String uri, String localName,
        String qName) throws SAXException {


        if (qName.equalsIgnoreCase("CLUSTER")) 
            {
            update(rc);
            rc.clear();
            }

}

    public void characters(char ch[], int start, int length) throws SAXException {
        if (name) 
        {
            String e= new String(ch, start, length);
            rc.put(e,e);
            name = false;
        }

    }

     };

       saxParser.parse("small.xml", handler);

     } catch (Exception e) {
       e.printStackTrace();
     }

   }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:49:11+00:00Added an answer on June 3, 2026 at 9:49 am

    Though I am completely confused by the title of question and this line of yours:

    but the rcset is not empty in the getrcset file ??

    If your question is why is sathiya empty ? The reason is that you are calling clear on rc after updating sathiya

    if (qName.equalsIgnoreCase("CLUSTER")) {
        update(rc);
        rc.clear();// This line is clearing the content of rc
    }
    

    Your program behavior is similar to this piece of code:

    Map<Integer, Map<String, String>> mainCont = new HashMap<Integer, Map<String,String>>();
    
    Map<String, String> content = new HashMap<String, String>();
    
    content.put("1", "1");
    
    mainCont.put(1, content);
    
    System.out.println(mainCont);
    
    content.clear();
    
    System.out.println(mainCont);
    

    In above code, mainCont is holding a reference to content, the moment content is cleared mainCont will show the updated value of content, since its referring to that object.

    But instead of content.clear(); if you make it content = new HashMap<String, String>();

    You will see that mainCont has all the values since now content points to a different object.

    Coming back to your code:

    Instead of :

    if (qName.equalsIgnoreCase("CLUSTER")) {
        update(rc);
        rc.clear();
    }
    

    do this:

    if (qName.equalsIgnoreCase("CLUSTER")) {
        update(rc);
        rc = new HashMap();
    }
    

    off topic:

    Consider using generics instead of using plain non safe Collections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is code which includes a variadic function and calls to the variadic function.
UPDATE: I've edited the code below to show what I was using when I
The Child constructor in the code below calls its parent constructor to initialise itself.
I have the Ruby code below, I am using windows API calls and I
I have ADO.Net code as below, that calls a stored procedure. Within the stored
I am using the below jquery code to call a ajax function in my
Below code : URL oracle = new URL(http://www.oracle.com/); URLConnection inputStream =oracle.openConnection(); InputStream in =
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has
I'm writing some JDBC code which calls a Oracle 11g PL/SQL procdedure which has
In the below code block I need to make sure initialize1 and initialize2 calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.