This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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>
 
 
subject: Parsing Nested XML Nodes
 
Similar Threads
Display contents in GUI format
help with web service to display xml file contents using netbeans
Unable to get the correct data from the XML file
Using XML in search criteria rather than hard coding it
parsing XML in java