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

  • SEARCH
  • Home
  • 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 7947939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:34:36+00:00 2026-06-04T01:34:36+00:00

I have one doubt regarding xml reading using Stax Parser. Expected Result: hq_seq_mast {SEQ_VAL=SEQ_VAL,

  • 0

I have one doubt regarding xml reading using Stax Parser.
Expected Result:

hq_seq_mast {SEQ_VAL=SEQ_VAL, 1=column,LAST_SEQ_VAL=LAST_SEQ_VAL, 2=column}
db_sequence_info{TNAME=TNAME, 3=column, CNAME=CNAME, 4=column}

Actual Result:

{hq_seq_mast={}, db_sequence_info={}}

What Mistake I have Done.

import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedHashMap;

public class SaxDiffChecker {
public static LinkedHashMap<String,LinkedHashMap<String,String>>FirstxmlCollection=new LinkedHashMap<String,LinkedHashMap<String,String>>();
public static LinkedHashMap<String,String> firstXml=new LinkedHashMap<String,String>();

public static String tableName=null;
public static String tableendElement=null;
public static String columendElement=null;
public static String characterElement=null;
public static String tempendElement=null;
public static String tempName=null;
public static String ntempName=null;
public static int key=0;

public void print(String fileLocation) {
    try {

        FileInputStream fileInputStream = new FileInputStream(fileLocation);
        XMLStreamReader xmlStreamReader =    XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream);
        while (xmlStreamReader.hasNext()) {
            printEventInfo(xmlStreamReader);
           }
        System.out.print("======="+FirstxmlCollection);
        xmlStreamReader.close();
    } catch (XMLStreamException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    } catch (FileNotFoundException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }
}


 private static void printEventInfo(XMLStreamReader reader) throws XMLStreamException {

    int eventCode = reader.next();


    switch (eventCode) {


        case 1 :

            //System.out.println("event = START_ELEMENT");
            //System.out.println("Localname = "+reader.getLocalName()+" Attribute Name"+reader.getAttributeValue(0));

            if("table".equalsIgnoreCase(reader.getLocalName())){

                tableName=reader.getAttributeValue(null,"name");
                tableendElement=reader.getLocalName();
            }else if("column".equalsIgnoreCase(reader.getLocalName())){
                columendElement=reader.getLocalName();
                firstXml.put(reader.getAttributeValue(0),reader.getAttributeValue(0));
            }else{
                tempendElement=reader.getLocalName();
            }
            break;
        case 2 :

            //System.out.println("event = END_ELEMENT");
            //System.out.println(tableendElement+"Localname = "+reader.getLocalName());
            if(tableendElement.length()>0 && tableendElement!=null && tableendElement.equalsIgnoreCase(reader.getLocalName())){
                System.out.println(tableName+"Heeee"+firstXml);
               FirstxmlCollection.put(tableName,firstXml);
               firstXml.clear();


            }else if(columendElement.length()>0 && columendElement!=null && columendElement.equalsIgnoreCase(reader.getLocalName())){
                firstXml.put(""+key++,columendElement);
            }
            break;
        case 3 :

            //System.out.println("event = PROCESSING_INSTRUCTION");
            //System.out.println("PIData = " + reader.getPIData());
            break;
        case 4 :

            //System.out.println("event = CHARACTERS");characterElement

            //System.out.println("Characters = " + reader.getText());
            break;
        case 5 :

            //System.out.println("event = COMMENT");
            //System.out.println("Comment = " + reader.getText());
            break;
        case 6 :

            System.out.println("event = SPACE");
            System.out.println("Space = " + reader.getText());
            break;
        case 7 :

            System.out.println("event = START_DOCUMENT");
            System.out.println("Document Started.");
            break;
        case 8 :

            //System.out.println("event = END_DOCUMENT");
            System.out.println("Document Ended");
            break;
        case 9 :

            //System.out.println("event = ENTITY_REFERENCE");
            //System.out.println("Text = " + reader.getText());
            break;
        case 11 :

            //System.out.println("event = DTD");
            //System.out.println("DTD = " + reader.getText());

            break;
        case 12 :

            //System.out.println("event = CDATA");
            //System.out.println("CDATA = " + reader.getText());
            break;
    }
}

public static void main(String[] args) {
    SaxDiffChecker eventsPrinter = new SaxDiffChecker();
    eventsPrinter.print("C:\\Users\\vellikutti\\Desktop\\bala.xml");


 }

}

xml:
<data-dictionary name="hq">
 <table engine-type="InnoDB" name="hq_seq_mast" scope="HQ">
 <columns>
  <column name="SEQ_VAL">
  <data-type>int(10)</data-type> 
  <nullable>false</nullable> 
 </column>
 <column name="LAST_SEQ_VAL">
   <data-type>int(10)</data-type> 
   <nullable>false</nullable> 
  </column>
 </columns>
 </table>
 <table engine-type="InnoDB" name="db_sequence_info" scope="HQ">
 <columns>
 <column name="TNAME">
 <data-type>varchar(30)</data-type> 
 <nullable>false</nullable> 
 </column>
 <column name="CNAME">
 <data-type>varchar(30)</data-type> 
 <nullable>false</nullable> 
  </column>
  </columns>
  </table>

  • 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-04T01:34:38+00:00Added an answer on June 4, 2026 at 1:34 am

    Here is your problem firstXml.clear(). The data is being cleared. You may want to make firstXml a local variable or set it to firstXml = new LinkedHashMap<String,String>();, instead of clearing it.

    Code Changes:

    //create new map instead of clearing saved map (remember - obj passed by ref)
    firstXml=new LinkedHashMap<String,String>();//firstXml.Clear();
    

    Result:

    hq_seq_mastHeeee [SEQ_VAL:SEQ_VAL, 0:column, LAST_SEQ_VAL:LAST_SEQ_VAL, 1:column]
    db_sequence_infoHeeee [TNAME:TNAME, 2:column, CNAME:CNAME, 3:column]
    Document Ended
    =======[hq_seq_mast:[SEQ_VAL:SEQ_VAL, 0:column, LAST_SEQ_VAL:LAST_SEQ_VAL, 1:column], db_sequence_info:[TNAME:TNAME, 2:column, CNAME:CNAME, 3:column]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one doubt regarding casting. public void Test(out T a, out T b)
I have a doubt in layouts.I have designed one layout using group layout using
I have one doubt regarding audio processing for noise reduction. Is there any free
I m just learning regular expression matching using javascript, and have a doubt regarding
I have a doubt regarding downloading data from a web service. One way is
I am using htmlspecialchars() function to prevent XSS attacks. I have doubt regarding what
I have a doubt regarding xml structured content in OpenCms. I have two XML
I have a doubt regarding database operation.I have one insert query that should run
I have one doubt in string . How can we acess the memory of
I have one doubt concerning c# method overloading and call resolution. Let's suppose I

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.