Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading/Parsing an XML doc Question

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
I have the following class which successfully reads and parses an XML doc. The problem is, it only reads the first <item> in the list.

What do I need to do in order to loop through the doc so that I can read the first few (or all) of the items? Here is my code:

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
How about calling selectNodes instead of selectSingleNode? Because the latter selects only a single node -- hence the name.
 
Russ Russell
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks! And then how do I loop through the items now that I amselecting multiple nodes?

Thanks again.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
selectNodes returns a java.util.List; I'm sure I don't need to tell you how to iterate over a List. Because the List isn't generic the only thing you'll need to do is cast the elements to Node; but you need to do that for selectSingleNode too.
 
Russ Russell
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks for the help so far.

I am VERY new to XML (and sort of new to Java).

It seems I am still only getting the first item. Does this look right?


I would like to print all the <item><description> elements in the entire document.

Thank you,
-Russ
    Bookmark Topic Watch Topic
  • New Topic