Quantcast
Viewing all articles
Browse latest Browse all 4

Processing RSS Feeds with Namespaces in Android

I'm trying to write an XML parser that takes an RSS feed & fetches the image urls shown in the url attribute of the <media:thumbnail> tag. This is all being done via android.Util.Xml, & is an adaptation of the code shown here. An example RSS feed that I'm trying to use is the BBC News RSS feed.

However, media is an additional namespace & (probably) as a result my parser isn't working as it should.

A version of my parse method is below. Is there any (no doubt simple) way to get my list of image URLs working?

public List<string> parse() {    URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml");    InputStream feedStream;    try {        feedStream = feedUrl.openConnection().getInputStream();    } catch (IOException e) {        throw new RuntimeException(e);    }                  final List<string> ret = new ArrayList<string>();    RootElement root = new RootElement("rss");    Element channel = root.getChild("channel");    Element item = channel.getChild("item");    item.getChild("media", "thumbnail").getChild("url").setEndTextElementListener(new EndTextElementListener() {        public void end(String body) {            ret.add(body);        }    });    try {        Xml.parse(feedStream, Xml.Encoding.UTF_8, root.getContentHandler());    } catch (Exception e) {        throw new RuntimeException(e);    }    return ret;}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>