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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:19:47+00:00 2026-05-27T16:19:47+00:00

This is one file which is stored in my res folder. I want to

  • 0

This is one file which is stored in my res folder. I want to parse this data.

<ROOT> 
<ROW Name="Product Name~B" CheckBox="" Type="PerformanceNormal"
Count="1" ChildCount="1" Show="Y" Refine="B"> 
   <COL Page="0" Image="" ProductID=""/> 
   <COL Page="1" Image="" ProductID="3">Sainsbury's aromatherapy citrus mint</COL> 
   <COL Page="1" Image="" ProductID="4">TestPerf</COL> 
   <COL Page="1" Image="" ProductID="5">TestPerf001</COL> 
   <COL Page="1" Image="" ProductID="24">Ashraf Product</COL> 
   <COL Page="2" Image="" ProductID="25">Acb</COL> 
</ROW> 
<ROW Name="Region~H" CheckBox="" Type="PerformanceNormal" Count="2" 
ChildCount="1" Show="Y" Refine="H"> 
   <COL Page="0" Image="" ProductID=""/> 
   <COL Page="1" Image="" ProductID="3">Western Europe</COL> 
   <COL Page="1" Image="" ProductID="4">Western Europe</COL> 
   <COL Page="1" Image="" ProductID="5">Western Europe</COL> 
   <COL Page="1" Image="" ProductID="24">Central and Eastern Europe</COL> 
   <COL Page="2" Image="" ProductID="25">Central and Eastern Europe</COL> 
</ROW> 
<ROW Name="Country~H" CheckBox="" Type="PerformanceNormal" 
Count="3" ChildCount="1" Show="Y" Refine="H"> 
   <COL Page="0" Image="" ProductID=""/> 
   <COL Page="1" Image="" ProductID="3">United Kingdom</COL> 
   <COL Page="1" Image="" ProductID="4">Belgium</COL> 
   <COL Page="1" Image="" ProductID="5">Belgium</COL> 
   <COL Page="1" Image="" ProductID="24">Czech Republic</COL> 
   <COL Page="2" Image="" ProductID="25">Czech Republic</COL> 
</ROW> 
</ROOT> 

I want tp parse all data name, checkbox,type this is row information

and inside ROW tag multiple COL tags are there i want get data from COL also following data
page,image,productID

through all data i want to make a table on the screen

please help me

  • 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-27T16:19:48+00:00Added an answer on May 27, 2026 at 4:19 pm

    Note:If it is not useful then please ignore this.

    I found myself to answer my question following way we can separate out (print)all details
    we can do it using to parser
    1)DOM parser
    2)SAX parser

    public void ReadAndPrintXMLfileUsingDOM()
        {
    
            try {
                  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                  InputStream rStream = null;
                    try
                    {
                        rStream = getClass().getResourceAsStream("sample.xml");;
                    }catch (Exception e) 
                    {
                        System.out.println(e.getMessage());
                    }
                    Document doc = docBuilder.parse(rStream);
                    doc.getDocumentElement ().normalize ();
                    System.out.println ("Root element of the doc is " + 
                    doc.getDocumentElement().getNodeName());
                    NodeList listOfPersons = doc.getElementsByTagName("ROW");
                    int totalPersons = listOfPersons.getLength();
                    System.out.println("Total no of people : " + totalPersons);
                    for(int s=0; s<listOfPersons.getLength() ; s++)
                    {
                        Node firstPersonNode = listOfPersons.item(s);
                        Element firstPersonElement = (Element)firstPersonNode;
                        System.out.println( "==============Name value = " + firstPersonElement.getAttribute( "Name" ) );
                        System.out.println( "===============CheckBox value = " + firstPersonElement.getAttribute( "CheckBox" ));
                        System.out.println( "==============Type value = " + firstPersonElement.getAttribute( "Type" ));
                        System.out.println( "==============Count value = " + firstPersonElement.getAttribute( "Count" ));
                        System.out.println( "==============ChildCount value = " + firstPersonElement.getAttribute( "ChildCount" ));
                        System.out.println( "==============Show value = " + firstPersonElement.getAttribute( "Show" ));
                        System.out.println( "==============Refine value = " + firstPersonElement.getAttribute( "Refine" ));
                        NodeList firstNameList = firstPersonElement.getElementsByTagName("COL");
    
                        int child_lng=firstNameList.getLength();
                        for(int j=0;j<child_lng;j++)
                        {
                              Node innernode=firstNameList.item(j);
                              Element firstPersonElement1 = (Element)innernode;
                              NamedNodeMap attributes = innernode.getAttributes();
                                Node value=firstNameList.item(j).getChildNodes().item(0); 
                              System.out.println( "==============Page value = " + firstPersonElement1.getAttribute( "Page" ) );
                              System.out.println( "==============Image value = " + firstPersonElement1.getAttribute( "Image" ) );
                              System.out.println( "==============ProductID value = " + firstPersonElement1.getAttribute( "ProductID" ) );
                              System.out.println("+++++++++++++++Node Value : " +value.getNodeValue());
    
                        }
                     }
              }catch (SAXParseException err) 
              {
                  System.out.println ("** Parsing error" + ", line " 
                   + err.getLineNumber () + ", uri " + err.getSystemId ());
                  System.out.println(" " + err.getMessage ());
              }catch (SAXException e) 
              {
                  Exception x = e.getException ();
                  ((x == null) ? e : x).printStackTrace ();
              }catch (Exception t) 
              {
                  System.out.println(t.getMessage());
              }
        }
    

    second method is

    public void ReadAndWriteXMLFileUsingSAXParser(){
    
            try
            {
                DefaultHandler handler = new MyHandler();
    //              parseXmlFile("infilename.xml", handler, true);
                SAXParserFactory factory = SAXParserFactory.newInstance();
                SAXParser saxParser = factory.newSAXParser();
                InputStream rStream = null;
                rStream = getClass().getResourceAsStream("sample.xml");
                saxParser.parse(rStream, handler);
            }catch (Exception e) 
            {
                System.out.println(e.getMessage());
            }
    
        }
    }
    class MyHandler extends DefaultHandler {
        String rootname;Attributes atr;
        private boolean flag=false;
        public void startElement(String namespaceURI, String localName,
                                 String qName, Attributes atts)  {
         rootname=localName;
         atr=atts;
         if(rootname.equalsIgnoreCase("ROW")){
             flag=true;
             int length = atts.getLength();
             for (int i=0; i<length; i++) {
                 String name = atts.getQName(i);
                 String value = atts.getValue(i);
                 System.out.println(name+"**********"+value);
             } 
         }
    
    
        }
        public void characters(char[] ch, int start, int length){
            String value=new String(ch,start,length);
            if(flag)
            {
                if(rootname.equalsIgnoreCase("COL")){
                     int length2 = atr.getLength();
                     for (int i=0; i<length2; i++) {
                         String name1 = atr.getQName(i);
                         String value1 = atr.getValue(i);
                         System.out.println(name1+"**********"+value1);
                     } 
                    System.out.println("++++++++++++++"+value);
                }
            }
    
        }
        public void endElement(String uri, String localName, String qName){
            rootname=localName;
             if(rootname.equalsIgnoreCase("ROW")){
                 flag=false;
             }
        }
    }
    

    we got output as when DOM parser

    Root element of the doc is ROOT
    Total no of people : 3
    ==============Name value = Product Name~B
    ===============CheckBox value = 
    ==============Type value = PerformanceNormal
    ==============Count value = 1
    ==============ChildCount value = 1
    ==============Show value = Y
    ==============Refine value = B
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 3
    +++++++++++++++Node Value : Sainsbury's aromatherapy citrus mint
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 4
    +++++++++++++++Node Value : TestPerf
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 5
    +++++++++++++++Node Value : TestPerf001
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 24
    +++++++++++++++Node Value : Ashraf Product
    ==============Page value = 2
    ==============Image value = 
    ==============ProductID value = 25
    +++++++++++++++Node Value : Acb
    ==============Name value = Region~H
    ===============CheckBox value = 
    ==============Type value = PerformanceNormal
    ==============Count value = 2
    ==============ChildCount value = 1
    ==============Show value = Y
    ==============Refine value = H
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 3
    +++++++++++++++Node Value : Western Europe
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 4
    +++++++++++++++Node Value : Western Europe
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 5
    +++++++++++++++Node Value : Western Europe
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 24
    +++++++++++++++Node Value : Central and Eastern Europe
    ==============Page value = 2
    ==============Image value = 
    ==============ProductID value = 25
    +++++++++++++++Node Value : Central and Eastern Europe
    ==============Name value = Country~H
    ===============CheckBox value = 
    ==============Type value = PerformanceNormal
    ==============Count value = 3
    ==============ChildCount value = 1
    ==============Show value = Y
    ==============Refine value = H
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 3
    +++++++++++++++Node Value : United Kingdom
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 4
    +++++++++++++++Node Value : Belgium
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 5
    +++++++++++++++Node Value : Belgium
    ==============Page value = 1
    ==============Image value = 
    ==============ProductID value = 24
    +++++++++++++++Node Value : Czech Republic
    ==============Page value = 2
    ==============Image value = 
    ==============ProductID value = 25
    +++++++++++++++Node Value : Czech Republic
    

    out as when SAXParsing

    Name**********Product Name~B
    CheckBox**********
    Type**********PerformanceNormal
    Count**********1
    ChildCount**********1
    Show**********Y
    Refine**********B
    Page**********1
    Image**********
    ProductID**********3
    ++++++++++++++Sainsbury's aromatherapy citrus mint
    Page**********1
    Image**********
    ProductID**********4
    ++++++++++++++TestPerf
    Page**********1
    Image**********
    ProductID**********5
    ++++++++++++++TestPerf001
    Page**********1
    Image**********
    ProductID**********24
    ++++++++++++++Ashraf Product
    Page**********2
    Image**********
    ProductID**********25
    ++++++++++++++Acb
    Name**********Region~H
    CheckBox**********
    Type**********PerformanceNormal
    Count**********2
    ChildCount**********1
    Show**********Y
    Refine**********H
    Page**********1
    Image**********
    ProductID**********3
    ++++++++++++++Western Europe
    Page**********1
    Image**********
    ProductID**********4
    ++++++++++++++Western Europe
    Page**********1
    Image**********
    ProductID**********5
    ++++++++++++++Western Europe
    Page**********1
    Image**********
    ProductID**********24
    ++++++++++++++Central and Eastern Europe
    Page**********2
    Image**********
    ProductID**********25
    ++++++++++++++Central and Eastern Europe
    Name**********Country~H
    CheckBox**********
    Type**********PerformanceNormal
    Count**********3
    ChildCount**********1
    Show**********Y
    Refine**********H
    Page**********1
    Image**********
    ProductID**********3
    ++++++++++++++United Kingdom
    Page**********1
    Image**********
    ProductID**********4
    ++++++++++++++Belgium
    Page**********1
    Image**********
    ProductID**********5
    ++++++++++++++Belgium
    Page**********1
    Image**********
    ProductID**********24
    ++++++++++++++Czech Republic
    Page**********2
    Image**********
    ProductID**********25
    ++++++++++++++Czech Republic
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into
I have one binary file which I have created. In it, data is stored
I have one binary file which I have created. In it, data is stored
I have one desktop application which was implemented in C#. This app uploads file
I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws
I have one file (for example: test.txt), this file contains some lines and for
I have opened one file with following way: fp = fopen(some.txt,r); Now in this
Banging my head on this one... I used tar -cvpzf file.tar.gz to compress a
I've seen this one-liner perl -lane '$_{$F[0]}+=$F[1]}print$_ $_{$_}for keys%_;{' file here: How can I
Man, stumped on this one. Trying to download a file with AFNetworking and the

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.