I’m using Android’s XML parsing helper (android.util.Xml.parse(InputStream, Encoding, ContentHandler) to parse this RSS feed: http://www.rssweather.com/wx/nz/christchurch/rss.php. It doesn’t seem to recognise the content:encoded tag, which contains the data I am trying to retrieve. Here is the structure of the XML:
<rss>
<channel>
<item>
<title>...</title>
<pubDate>...</pubDate>
// Other tags
<content:encoded>
<![CDATA[
(.... this is what I want to retrieve ...)
]]>
</content:encoded>
</item>
</channel>
</rsss>
This is my code:
void parse(){
RootElement root = new RootElement("rss");
Element channel = root.getChild("channel");
Element item = channel.getChild("item");
Element contentEncoded = item.getChild("content", "encoded");
// Have also tried these two:
Element encoded = item.getChild("encoded");
Element content = item.getChild("content");
contentEncoded.setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
Log.d("Test", "Content found: " + body);
}
});
try {
Xml.parse(feedUrl.openConnection().getInputStream(),
Xml.Encoding.UTF_8, root.getContentHandler());
} catch (Exception e){
throw new RuntimeException(e);
}
}
Where have I gone wrong? 🙂 I can retrieve the other data from the <item> element such as the title or pubDate without trouble; it’s only the content:encoded that eludes me.
You can stick with your Android Sax Parser. I’ve faced the same problem and the solution to use content namespace and “encoded” as element.
You will find content namespace in the rss element:
So getting the Element looks like this: