This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I'm trying to parse some RSS feeds for my website, and I'm not really sure where to start. Can anyone recommend any tutorials or articles? Should I use SAX or DOM to do it?
Pavel Halas
Ranch Hand
Joined: Jul 05, 2003
Posts: 35
posted
0
I recommend you legendary tutorial/faq web by Roseanne Zhang. My opinion is to use JDOM, parsing this way...
Chris Stewart
Ranch Hand
Joined: Sep 14, 2002
Posts: 184
posted
0
Ok, after some reading, here I am... For some reason the node_x.getNodeValue call doesn't return the text, can anybody help me figure out why?
fei long
Ranch Hand
Joined: Apr 04, 2002
Posts: 48
posted
0
If I am remember correctly, the 'ELEMENT' node type has broader range. So can you check the nodetype static variable again and try 'TEXTNODE' or something like that? Hope this helps you.
Chris Stewart
Ranch Hand
Joined: Sep 14, 2002
Posts: 184
posted
0
That didn't work for me either. :dunno: [ July 21, 2003: Message edited by: Chris Stewart ]
Naren
Greenhorn
Joined: Jul 21, 2003
Posts: 23
posted
0
in the inner most loop of your code, you got to the point where you can print the node name. For example, "title" <title>Open source or no: Let the market decide</title> The node you are examining at this point has a node name "title" and node value "null". I assume you are trying to print the text "Open source....". It is represented by the child node and this child node has a node name "#text" (or null for some parsers) and the node value "Open source..." To get your program working, get the child node, check it's Node type (Node.TEXT_NODE) and then get the NodeValue.
<a href="http://www.mqtips.com" target="_blank" rel="nofollow">MQMessenger</a> - free Java app for MQSeries
Chris Stewart
Ranch Hand
Joined: Sep 14, 2002
Posts: 184
posted
0
Perfect, thank you! This is my final code:
Naren
Greenhorn
Joined: Jul 21, 2003
Posts: 23
posted
0
you can remove a lot of lines from your code using the call getElementsByTagName("tag_name"). I use this function to get the value of a node:
the 'for' loop inside is just to be safe with all sorts of parser implementations. The text value of the node is represented, some times, in multiple child nodes.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Moving to the XML forum.
"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.