This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Need Help Iterating Elements Using dom4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Need Help Iterating Elements Using dom4j" Watch "Need Help Iterating Elements Using dom4j" New topic
Author

Need Help Iterating Elements Using dom4j

Russ Russell
Ranch Hand

Joined: Jan 24, 2010
Posts: 72
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
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help Iterating Elements Using dom4j
 
Similar Threads
a ReadXMLFile Servlet works without my expectation...
help!Urgent,my assignment.....
Reading/Parsing an XML doc Question
Need to modify xml using dom4j
Stateful Session Bean - Conversational State