I have done the coding for parsing the below shown XML code using NanoXml.But when I tried to add more tags into the XML code I am failing to do so.
This is the code XML that I successfully parsed.
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<item>
<title>Spain Winner Of FIFA World Cup 2010</title>
<link>http://www.fifa.com/worldfootball/news/newsid=1862843.html</link>
<description>It is World Cup 2010 Day 27 and Spain beat Netherlands 1 to 0 during extra time emerging as the winner of FIFA World Cup 2010! It is the first time Spain has won the World Cup.</description>
</item>
<item>
<title>Dutch still proud despite the pain</title>
<link>http://www.fifa.com/worldfootball/news/newsid=1274347.html</link>
<description>FIFA World Cup runners-up Netherlands will receive the acclaim of their countrymen on a canal tour of Amsterdam on Saturday and they have every reason to feel proud.</description>
</item>
<item>
<title>The Old Continent gears up</title>
<link>http://www.fifa.com/worldfootball/news/newsid=1234567.html</link>
<description>FIFA.com takes a look at the European continent, as many countries count down to the start of their newseasons and international coaches look to wipe the slate clean.</description>
</item>
</channel>
</rss>
And this is the code I have written to make that happen:
try{
URL url = new URL("http://localhost:8080/examples/rss.xml");
URLConnection connection = url.openConnection();
WriteLog.logString("Success!Opening the file URL ");
this.parser = XMLParserFactory.createDefaultXMLParser();
IXMLReader reader = new StdXMLReader(connection.getInputStream());
this.parser.setReader(reader);
IXMLElement xml = (IXMLElement)this.parser.parse();
this.itemDetails = xml.getFirstChildNamed("channel");
this.items = this.itemDetails.enumerateChildren();
while (this.items.hasMoreElements())
{
for (int i=0;i<3;i++)
{
final IXMLElement item = (IXMLElement) this.items.nextElement();
this.Title[i]=item.getFirstChildNamed("title").getContent();
this.Link[i]=item.getFirstChildNamed("link").getContent();
this.Desc[i]=item.getFirstChildNamed("description").getContent();
WriteLog.logString("Title: "+this.Title[i]+"\n\n"+"Link: "+this.Link[i]+"\n"+"\n"+"Description: "+this.Desc[i]+"\n"+"\n");
}
}
}
catch (Exception excep)
{
WriteLog.logString("Error! from Exception(IN CATALOGPARSER)"+excep.getMessage());
excep.printStackTrace();
}
}
The above part is working smoothly.This is what I wanted to achieve..
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
**<title>BBC News - News front page</title>
<link>http://www.bbc.co.uk/news/video_and_audio/news_front_page/</link>
<description>
The latest stories from the News front page section of the
BBC News web site.
</description>
<language>en-gb</language>
<lastBuildDate></lastBuildDate>
<copyright>
Copyright: (C) British Broadcasting Corporation,
see http://news.bbc.co.uk/2/hi/help/rss/4498287.stm
for terms and conditions of reuse.
</copyright>**
<item>
<title>Spain Winner Of FIFA World Cup 2010</title>
<link>http://www.fifa.com/worldfootball/news/newsid=1862843.html</link>
<description>It is World Cup 2010 Day 27 and Spain beat Netherlands 1 to 0 during extra time emerging as the winner of FIFA World Cup 2010! It is the first time Spain has won the World Cup.</description>
</item>
<item>
<title>Dutch still proud despite the pain</title>
<link>http://www.fifa.com/worldfootball/news/newsid=1274347.html</link>
<description>FIFA World Cup runners-up Netherlands will receive the acclaim of their countrymen on a canal tour of Amsterdam on Saturday and they have every reason to feel proud.</description>
</item>
<item>
<title>The Old Continent gears up</title>
<link>http://www.fifa.com/worldfootball/news/newsid=1234567.html</link>
<description>FIFA.com takes a look at the European continent, as many countries count down to the start of their newseasons and international coaches look to wipe the slate clean.</description>
</item>
</channel>
</rss>