• Post Reply 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

Need Help Iterating Elements Using dom4j

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to iterate through and print all the <item><description> elements in an XML doc. My code (below) only returns the first <item><description> element. How do I get them all?

Thank you,
-Russ

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know dom4j, but that line 49 looks fishy to me. You already got nodes which matched /rss/channel/item/description, so once you have them you shouldn't have to provide any XPath expression to get them. Or whatever you meant that to be.

My guess is that the //user//description string is being used as an XPath expression. So it returns all of the nodes which you already got earlier in the code, and then the valueOf() method necessarily selects just the first of them.

But I'm just guessing. I would say you don't need that line of code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic