This week's book giveaway is in the Game Development forum.
We're giving away four copies of Badass: Making Users Awesome and have Kathy Sierra on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Java XML DOM Parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Java XML DOM Parsing" Watch "Java XML DOM Parsing" New topic

Java XML DOM Parsing


Joined: Apr 11, 2006
Posts: 19
Trying to use DOM in java to parse RSS feeds. I think im going to crack up. Im trying to print everthing out to screen. Here an example of a feed im using.

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12911
You really didn't need to post that monsterous listing, just one item posted as code would have been sufficient.
What you needed to post but didn't is exactly what your problem is?
Have you worked through one of the numerous tutorials on DOM parsing such as this one?
What have you tried so far? What happens when you try it?

Joined: Apr 11, 2006
Posts: 19
Right here my sample feed bit smaller and code

The result is it says there are three child elements, but there are alot more than three child elements. What's going on. Its the channel tag im thinking how do i get beyond it or set it as the root element.
[ April 22, 2006: Message edited by: Paul Donaghy ]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19357

The result is it says there are three child elements, but there are alot more than three child elements.
No, unsurprisingly the result is correct (except there are actually three child nodes). The document element is an <rss> element. And under that there are indeed three child nodes:

1. A whitespace text node containing a linefeed character.
2. A <channel> element.
3. Another whitespace text node.

That's it. I suppose your confusion would be partly cleared up if you had an indented listing of the XML document. Then it would be more apparent that the <channel> element itself has quite a few child nodes; many of them are <item> elements that in turn have their own children.

You can traverse this tree structure by writing appropriate DOM code. I won't post any DOM code here because (a) I hate writing DOM code and I would rather use XSLT whenever it's necessary to extract data from XML, and (b) William Brogden already provided a link to a tutorial with DOM code.
I agree. Here's the link:
subject: Java XML DOM Parsing