Atom RSS Parser Android

by GarciaPL on Wednesday 21 January 2015

One of my Android applications requires to fetch and process external RSS resource. My first thought was that I should use very useful and well documented library called ROME [1]. Unfortunately I had some difficulties using this library because of there is a lack of java.beans package in Android's Java API implementation [2]. Of course you can fix this issue by installing some missing packages, but I was looking for some out-of-box solution. Finally, I found library called Simple Feed Parser [3]. It may for some of you be quite outdated (last commit was 4 years ago) and I found that there is a some issue with accessing date of single RSS entry, but it has very simple implementation, it is compatible with Android SDKs and it does not require any further library dependencies! Below you can find some example usage of this library in Java.

import com.ernieyu.feedparser.Feed;
import com.ernieyu.feedparser.FeedException;
import com.ernieyu.feedparser.FeedParser;
import com.ernieyu.feedparser.FeedParserFactory;
import com.ernieyu.feedparser.Item;

try {
                InputStream inputstream = new URL("http://rss.android.com/rss).openStream();
                FeedParser parser = FeedParserFactory.newParser();
                Feed feed = parser.parse(inputstream);
                List itemList = feed.getItemList();
                for (Item item : itemList) {
                    logger.info("Title : " + item.getTitle());
                    logger.info("Item : " + item.getLink());
                    logger.info("Description : " + item.getDescription());
                    logger.info("Date : " + item.getPubDate()); //might be null
                }
            } catch (IOException e) {
                logger.info("IOException : " + e.getMessage());
            } catch (FeedException e) {
                logger.info("FeedException : " + e.getMessage());
            }

References :  [1] ROME - All feeds lead to Rome! [2] Java.Beans on Android [3] Simple Feed Parser