I am using JDOM parser to parse a XML i created using feedrinse.
XML is available at: http://www.feedrinse.com/services/rinse/?rinsedurl=396ac3b0142bb6360003c8dbac4f8d47
My code is to parse every title,link,pubDate element and store them in a new XML which i am sending to front end. Here is my code:
String temp = "http://www.feedrinse.com/services/rinse/?rinsedurl=396ac3b0142bb6360003c8dbac4f8d47";
String XMLstr="<FEED>";
SAXBuilder builder = new SAXBuilder();
URL url= new URL(temp);
Document doc = null;
try{
doc=builder.build(url);
Element root = doc.getRootElement();
//List children = root.getChildren();
List list = root.getChildren("item");
XMLstr+="<children>"+list.size()+"</children>";
for (int i = 0; i < list.size(); i++) {
Element node = (Element) list.get(i);
String title=node.getChildText("title").toString();
XMLstr+="<title>"+title+"</title>";
String link=node.getChildText("link").toString();
XMLstr+="<link>"+link+"</link>";
String desc=node.getChildText("description").toString();
XMLstr+="<desc>"+desc+"</desc>";
String pubDate=node.getChildText("pubDate").toString();
XMLstr+="<pubDate>"+pubDate+"</pubDate>";
}
}
catch(Exception e)
{
out.println(e);
}
XMLstr+="</FEED>";
However, it is not parsing correctly. At first it always show children size as 0. Please suggest what mistake i am doing and how can i rectify the same. Thanks.