Jump to content
  • Advertisement
Sign in to follow this  
anda

(Java) reading file with XML DOM problem

This topic is 3716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Never mind it's solved. Hi, I'm trying to read an xml file that looks like:
<root>
   <item>
      <someinfo>a</someinfo>
   </item>
   <item>
      <someinfo>a</someinfo>
      <otherinfos></otherinfos>
   </item>
   <item>
      <someinfo>b</someinfo>
      <otherinfos>
         <otherinfo>otherstuff</otherinfo>
      </otherinfos>
   </item>
   <item>
      <someinfo>b</someinfo>
      <otherinfos>
         <otherinfo>otherstuff2</otherinfo>
         <otherinfo>otherstuff3</otherinfo>
      </otherinfos>
   </item>
</root>


I don't know how to access the 'otherinfo' nodes. Heres my code so far:
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("myfile.xml");

NodeList itemList = doc.getElementsByTagName("item");

for(int i=0;i<itemList.getLength();i++) {
   Element someinfoElement = (Element)doc.getElementsByTagName("someinfo").item(i); //probably not the best way to read nodes.

   //now how to check if an 'item' node contains any 'otherinfo' nodes and then read them?
}


Thank you. [Edited by - anda on May 14, 2008 12:24:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!