• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help Iterating Elements Using dom4j

 
Russ Russell
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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

 
Paul Clapham
Sheriff
Pie
Posts: 20976
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic