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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:34:49+00:00 2026-06-18T07:34:49+00:00

i am trying to parse the following xml file using Dom parser.but i am

  • 0

i am trying to parse the following xml file using Dom parser.but i am getting the first three Tags
(Date, Breakfast,Lunch).how to get all Date,Breakfast and Lunch Tags.

-<Content>
  <Date>2/4/2013</Date>
  <Breakfast>WG Biscuit, Grits, sausage patty, fruit, juice, milk</Breakfast>
  <Lunch>Chicken tenders with sauce, WG affle stick and syrup, carrots-MC, romaine garden salad, fruit, juice, milk</Lunch>
  <Date>2/5/2013</Date>
  <Breakfast>grilleed cheese sandich, grits, fruit, juice, milk</Breakfast>
  <Lunch>meat sauce w/WG pasta, green beans, caesar salad, WW garlic toast, fruit, juice, milk</Lunch>
  <Date>2/6/2013</Date>
  <Breakfast>WG biscuit with chicken patty, fruit, juice, milk</Breakfast>
  <Lunch>WG pizza, spinach salad, WKcorn, fruit, juice, milk</Lunch>
  <Date>2/7/2013</Date>
  <Breakfast>WG french toast sticks (4), sausage links, fruit, juice, milk</Breakfast>
  <Lunch>salisbury steak, black eyed peas, creamed potatoes with gravy, greens-MC, spring mixed salad, WW cornbread, fruit, juice, milk</Lunch>
  <Date>2/8/2013</Date>
  <Breakfast>WG breakfast bagel, yogurt, fruit, juice, milk</Breakfast>
  <Lunch>BBQ rib portion on WG bun, sweet potato fries or yams, romaine garden salad, fruit, juice, milk</Lunch>
  <Date>2/11/2013</Date>
  <Breakfast>Mardi Gras Holiday - No School</Breakfast>
  <Lunch/>
</Content> 

i am using the following code:

StringBuilder sb=new StringBuilder(arg0[0]);
             String findlink=sb.toString();
             try{
                    HttpClient client=new DefaultHttpClient();
                    HttpGet request=new HttpGet();
                    request.setURI(new URI(findlink)) ;

                    HttpResponse response=client.execute(request);
                    //et.setText("its working"); 
                 DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

                 DocumentBuilder Builder=factory.newDocumentBuilder();
                 dom=Builder.parse(response.getEntity().getContent());
                 dom.getDocumentElement().normalize();
                  nList5=dom.getElementsByTagName("Content");
                    for(int temp=0;temp<nList5.getLength();temp++)
                    {
                         Node nNode=nList5.item(temp);
                         if(nNode.getNodeType()==Node.ELEMENT_NODE)
                         {
                                    Element eElement=(Element)nNode;
                                    String  base1 =getTagValue("Date",eElement);
                                    Date.add(base1);
                                    String  base2 =getTagValue("Breakfast",eElement);
                                    Breakfast.add(base2);
                                    String  base3 =getTagValue("Lunch",eElement);
                                    Lunch.add(base3);


                          }
                    }

how to parse all tags under content.help me in doing this.

  • 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-18T07:34:50+00:00Added an answer on June 18, 2026 at 7:34 am

    first make sure that your XML data is formatted I mean it should not miss any tag closing and braces <> use any online XML formator to validate your XML. after this try following code.

    XMLParser Function

    /**
     * Getting XML DOM element
     * 
     * @param XML
     *            string
     * */
    public Document getDomElement(String xml) {
        Document doc = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    
        dbf.setCoalescing(true);
        try {
    
            DocumentBuilder db = dbf.newDocumentBuilder();
    
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is);
    
        } catch (ParserConfigurationException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (SAXException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (IOException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        }
    
        return doc;
    
    }
    

    getting NODE Value.

    /**
     * Getting node value
     * 
     * @param Element
     *            node
     * @param key
     *            string
     * */
    public String getValue(Element item, String str) {
        NodeList n = item.getElementsByTagName(str);
        return this.getElementValue(n.item(0));
    }
    

    }

    call above function like this

                Document doc = parser.getDomElement(yourXMLString);
                NodeList nl = doc.getElementsByTagName("Content");
    
                for (int i = 0; i < nl.getLength(); i++) {
    
                    Element e = (Element) nl.item(i);
    
                    // Get your Data Here
    
                                    String  base1 =getTagValue("Date",eElement);
                                    Date.add(base1);
                                    String  base2 =getTagValue("Breakfast",eElement);
                                    Breakfast.add(base2);
                                    String  base3 =getTagValue("Lunch",eElement);
                                    Lunch.add(base3);
    
            }
    

    Change your XML Like this

    <Contents>
    <content>
    <Date>2/4/2013
    </Date>
    <Breakfast>WG Biscuit, Grits, sausage patty, fruit, juice, milk
    </Breakfast>
    <Lunch>Chicken tenders with sauce, WG affle stick and syrup, carrots-MC, romaine garden salad, fruit, juice, milk
    </Lunch>
    </content>
    <content>
    <Date>2/5/2013
    </Date>
    <Breakfast>grilleed cheese sandich, grits, fruit, juice, milk
    </Breakfast>
    <Lunch>meat sauce w/WG pasta, green beans, caesar salad, WW garlic toast, fruit, juice, milk
    </Lunch>
    </content>
    <content>
    <Date>2/6/2013
    </Date>
    <Breakfast>WG biscuit with chicken patty, fruit, juice, milk
    </Breakfast>
    <Lunch>WG pizza, spinach salad, WKcorn, fruit, juice, milk
    </Lunch>
    </content>
    <content>
    <Date>2/7/2013
    </Date>
    <Breakfast>WG french toast sticks (4), sausage links, fruit, juice, milk
    </Breakfast>
    <Lunch>salisbury steak, black eyed peas, creamed potatoes with gravy, greens-MC, spring mixed salad, WW cornbread, fruit, juice, milk
    </Lunch>
    </content>
    <content>
    <Date>2/8/2013
    </Date>
    <Breakfast>WG breakfast bagel, yogurt, fruit, juice, milk
    </Breakfast>
    <Lunch>BBQ rib portion on WG bun, sweet potato fries or yams, romaine garden salad, fruit, juice, milk
    </Lunch>
    </content>
    <content>
    <Date>2/11/2013
    </Date>
    <Breakfast>Mardi Gras Holiday - No School
    </Breakfast>
    <Lunch />
    </content>
    </Contents>
    

    and call this NodeList nl = doc.getElementsByTagName("Content");

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

Sidebar

Related Questions

I am trying to parse the following using Dom parser in Android. <offerURL> http://statTest.dealtime.com/DealFrame/DealFrame.cmp?bm=553&BEFID=93767&aon=%5E1&MerchantID=434524&crawler_id=1909400&dealId=TCk4NTG97Aa3wSQgh2U3FQ%3D%3D&url=http%3A%2F%2Frover.ebay.com%2Frover%2F1%2F707-64686-24023-0%2F2%3Fipn%3Dpsmain%26icep_item_id%3D190622592957%26icep_vectorid%3D260601%26kwid%3D1%26mtid%3D637%26crlp%3D1_260601%26kw%3D%7Bquery%7D%26query%3D%7Bquery%7D%26linkin_id%3D%7Blinkin_id%7D%26sortbid%3D%7Bbidamount%7D%26fitem%3D190622592957%26mt_id%3D637&linkin_id=7000251&Issdt=120323134700&searchID=p2.77722a731149145f60fa&DealName=Samsung+B2100+Outdoor+In+Schwarz+%28black%29+Orig.+Neuware&dlprc=89.95&crn=&istrsmrc=1&isathrsl=0&AR=1&NG=3&NDP=6&PN=1&ST=7&DB=sdcprod&MT=phx-pkadu-intl-dc20&FPT=DSP&NDS=&NMS=&MRS=&PD=95929320&brnId=14863&IsFtr=0&IsSmart=0&DMT=&op=&CM=&DlLng=7&RR=1&cid=&semid1=&semid2=&IsLps=0&CC=0&SL=0&FS=1&code=&acode=538&category=&HasLink=&frameId=&ND=&MN=&PT=&prjID=&GR=&lnkId=&VK=
I'm trying to parse XML -file using QXmlStreamReader . With following code I only
Trying to parse the following Python file using the lxml.etree.iterparse function. sampleoutput.xml <item> <title>Item
I'm trying to parse a MusicBraninz XML file in Delphi XE2 using the following
So I'm trying to parse the following XML document with C#, using System.XML: <root
I was trying to parse mathml document using JScience but was not succeed. Following
I'm trying to parse a file from the web on Android using the DOM
I'm trying to parse a XML file, but when loading it simpleXML prints the
I'm new to xml parsing, I am trying to parse the following xml file
I am trying to parse a large XML file using JavaScript. Looking online, it

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.