Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Not able to parse xml feed

  Asked By: Abarrane    Date: Jan 28    Category: Java    Views: 635
  

I'm trying to parse this xml feed here:

news.search.yahoo.com/.../inde\
x.html?p=dvd

But I can seem to get it to work. I have practiced in the past few months and
thought I got the hang of JAXP but this file is making me doubt myself again.
All I want to do is take the data from the title, link, pubDate, and description
tags out of the item tags and load into an ArrayList. (with the exception of
that first really big item tag).

Here is my code -->

Element newsRoot = xml_Doc.getDocumentElement();

NodeList items = newsRoot.getElementsByTagName("item");

for (int i = 0; i < items.getLength(); i++)
{
//Node item = items.item(i);

//getting the title tag
NodeList title = newsRoot.getElementsByTagName("title");
Node item = title.item(i);
NodeList nl = item.getChildNodes();
for (int j = 0; j < nl.getLength(); j++) {
Node i2 = nl.item(j);

if ( i2.getNodeType() == 4 ) {
String node_val = i2.getNodeValue();
News_al.add(node_val);
}
}

//getting the link tag
NodeList link = newsRoot.getElementsByTagName("link");
String slink = link.item(i).getFirstChild().getNodeValue();
News_al.add(slink);

//getting the pubDate tag
String pubDate =
newsRoot.getElementsByTagName("pubDate").item(i).getFirstChild().getNodeValue();
News_al.add(pubDate);

//getting the description tag
NodeList description= newsRoot.getElementsByTagName("description");
item = description.item(i);
nl = item.getChildNodes();
for (int j = 0; j < nl.getLength(); j++) {
Node i2 = nl.item(j);

if ( i2.getNodeType() == 4 ) {
String node_val = i2.getNodeValue();
News_al.add(node_val);
}
}

}

///End code

Does anyone see what I am doing wrong? Or am I not even close?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Not able to parse xml feed Or get search suggestion and latest updates.




Tagged: