Android native SAX Parser & choosing adequate root element

Cakeface

New Member
I've chosen the Android's SAX Parser to perform rss and atom parsing because of it's simplicity. The parser works perfectly on pure rss feeds (not the combined rss and atom feeds I've found arround the web), but I need to extend it's functionality to read atom feeds. How could I detect if it is a rss or atom feed with the SAX Parser?Thanks in advance
The Http connection:\[code\]URL rssUrl = new URL(url);URLConnection connection = rssUrl.openConnection();InputStream stream = connection.getInputStream();\[/code\]Here's the SAX Code:\[code\]public class XMLParser {private FeedListItem feedActual;private ArrayList<FeedListItem> parseRSS(InputStream input,final long pageId) { final ArrayList<FeedListItem> feeds = new ArrayList<FeedListItem>(); RootElement root = new RootElement("rss"); Element channel = root.getChild("channel"); Element item = channel.getChild("item"); item.setStartElementListener(new StartElementListener(){ public void start(org.xml.sax.Attributes attributes) { feedActual = new FeedListItem(pageId); } }); item.setEndElementListener(new EndElementListener(){ public void end() { feeds.add(feedActual); } }); item.getChild("title").setEndTextElementListener( new EndTextElementListener(){ public void end(String body) { feedActual.setTitle(body); } }); item.getChild("link").setEndTextElementListener( new EndTextElementListener(){ public void end(String body) { feedActual.setUrl(body); } }); item.getChild("description").setEndTextElementListener( new EndTextElementListener(){ public void end(String body) { feedActual.setContent(Html.fromHtml(body).toString()); } }); item.getChild("pubDate").setEndTextElementListener( new EndTextElementListener(){ public void end(String body) { feedActual.setDate(body); } }); try { Xml.parse(input, Xml.Encoding.UTF_8, root.getContentHandler()); } catch (Exception ex) { throw new RuntimeException(ex); } return feeds;}\[/code\]}
 
Back
Top