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 7639511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:26:10+00:00 2026-05-31T08:26:10+00:00

I need to read read values from below xml and am using saxparser for

  • 0

I need to read read values from below xml and am using saxparser for this, but am stuck while reading tag it appears multiple times and i am unable to read the next row tag, can any one help me….?

Whole data appear in between tag, and refers different Tables, and tage gives the set on records need to be inserted and refers Column name and value need to be inserted into that particular column .

 <?xml version="1.0" encoding="UTF-8"?>
<DATA>
<TABLEDATA name="web_order_header" rows="1">
<ROW>
<FIELD name="order_id"> 40403141201067683</FIELD>
<FIELD name="order_date"> Mar 14 , 2012</FIELD>
<FIELD name="company_name">Testing</FIELD>
<FIELD name="company_website"> N/A </FIELD>
<FIELD name="customer_firstname">uni</FIELD>
<FIELD name="customer_lastname">u</FIELD>
<FIELD name="email">aaa@xyz.com</FIELD>
<FIELD name="billto_contact">uni</FIELD>
<FIELD name="billto_phone">78784</FIELD>
<FIELD name="billto_phone_ext">N/A</FIELD>
<FIELD name="billto_address">ss</FIELD>
<FIELD name="billto_city">mys</FIELD>
<FIELD name="billto_state">Kar</FIELD>
<FIELD name="billto_zip">5678945</FIELD>
<FIELD name="shipto_contact">uni</FIELD>
<FIELD name="shipto_phone">78784</FIELD>
<FIELD name="shipto_phone_ext">N/A</FIELD>
<FIELD name="shipto_address">ss</FIELD>
<FIELD name="shipto_city">mys</FIELD>
<FIELD name="shipto_state">Kar</FIELD>
<FIELD name="shipto_zip">5678945</FIELD>
</ROW>
</TABLEDATA>

<TABLEDATA name="web_order_detail" rows="3">
<ROW>
<FIELD name="order_id"> 40403141201067683</FIELD>
<FIELD name="qty">1</FIELD>
<FIELD name="item_id">JUS72-28250</FIELD>
<FIELD name="mfr">Justrite Manufacturing Co</FIELD>
<FIELD name="item_desc">EcoPolyBlend&amp;trade; Drum Collection Station For Spills</FIELD>
<FIELD name="uom">Each</FIELD>
<FIELD name="price">739.00</FIELD>
</ROW>
<ROW>
<FIELD name="order_id"> 40403141201067683</FIELD>
<FIELD name="qty">1</FIELD>
<FIELD name="item_id">COM62-CAS-B51V80-CA1B</FIELD>
<FIELD name="mfr">Compressed Air Systems</FIELD>
<FIELD name="item_desc">5HP 80 GAL 15CFM Reciprocating Air Compressor</FIELD>
<FIELD name="uom">Each</FIELD>
<FIELD name="price">1265.33</FIELD>
</ROW>
<ROW>
<FIELD name="order_id"> 40403141201067683</FIELD>
<FIELD name="qty">2</FIELD>
<FIELD name="item_id">KIM11-05701</FIELD>
<FIELD name="mfr">Kimberly Clark Corp</FIELD>
<FIELD name="item_desc">Wypall&amp;reg; 12.5&amp;quot; x 13&amp;quot; L40 Q-Fold White Towel</FIELD>
<FIELD name="uom">Case</FIELD>
<FIELD name="price">88.00</FIELD>
</ROW>
</TABLEDATA>
</DATA>

This is my JAVA code

public void readXml(Document requestDoc,PrintStream out)throws IOException, JDOMException, SQLException, ParseException {
             Document responseDoc = null;


             Element root = requestDoc.getRootElement();

             List tableNameList = root.getChildren("TABLEDATA");

             for(int i=0; i<tableNameList.size(); i++){
                 Element table = (Element) tableNameList.get(i);
                 String tableName = table.getAttribute("name").getValue();
                 int numOfRows = table.getAttribute("rows").getIntValue();
                 System.out.println(tableName+" : tableName---------------------- numOfRows : "+numOfRows);

                    List rowList = root.getChild("TABLEDATA").getChildren("ROW");
                    for(int j=0; j<rowList.size(); j++){
                        Element row = (Element) rowList.get(j);
                        System.out.println("row : "+rowList.size());

                        List fieldList =  root.getChild("TABLEDATA").getChild("ROW").getChildren("FIELD");
                        System.out.println("----------------------");
                        for(int k=0; k<fieldList.size(); k++){
                            Element field = (Element) fieldList.get(k);
                            String fieldName = field.getAttribute("name").getValue();
                            String fieldValue = field.getTextTrim();
                            System.out.println(fieldName+"----------------------"+fieldValue);
                        }
                        System.out.println("----------------------");
                    }


             }
  • 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-05-31T08:26:12+00:00Added an answer on May 31, 2026 at 8:26 am

    Your always looking at the first table and the first row. To fix it, use the current elements in the for loops.

    Replace

    List rowList = root.getChild("TABLEDATA").getChildren("ROW");
    

    with

    List rowList = table.getChildren("ROW");
    

    and

    List fieldList =  root.getChild("TABLEDATA").getChild("ROW").getChildren("FIELD");
    

    with

    List fieldList =  row.getChildren("FIELD");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using spring. I need to read values from properties file. This is
I am new to MySQLdb. I need to read values from a pre-defined database
I have an XML file, I need to extract values from it, and put
I'm trying to read specific values from the text file (below): Current Online Users:
I need to read a value from the terminal in a bash script. I
I need to read the value of a property from a file in an
I need to be able to read the value of my attribute from within
I need to read different values stored in a file one by one. So
I need to read from a variety of different text files (I've some delimited
I need to read selected files, matching on the file name, from a remote

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.