• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Java XML DOM Parsing

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 28395
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic