• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java XML DOM Parsing

 
Pauldon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Bill
 
Pauldon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic