This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Parsing Nested XML Nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing Nested XML Nodes" Watch "Parsing Nested XML Nodes" New topic
Author

Parsing Nested XML Nodes

Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
Hi guys,
I'm trying to parse a simple (to me) XML document with nested nodes that looks like this:


So I wrote a method to parse this file and it works except the number of <followers> is always 5 and the count is always 1.



Any ideas would be appreciated.

Thanks.
Chris>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I can't really read that code. Could you break it up into manageable chunks first?
Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
Okay, I figured it out, with help from Eclipse. Problem #1: <followers> are a sibling, not a child. Problem #2: I was confusing nodelist items with element items. Here's the answer:



Hope this helps someone else
Chris>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

<meta>Do you find this readable? I mean, I wasn't just saying that for *my* benefit, but yours too. Code like this takes too much time to re-understand.</meta>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing Nested XML Nodes
 
Similar Threads
Using XML in search criteria rather than hard coding it
parsing XML in java
help with web service to display xml file contents using netbeans
Unable to get the correct data from the XML file
Display contents in GUI format