views:

5872

answers:

8

Hello, I am trying to create my first Android application and I'm not all that experienced with Java development. In short, the application needs to do the following:

  • On click, fetch a RSS feed online
  • Parse it for data
  • Show the data

I've been browsing for guides, tutorials and documentation but the parsers I've found so far only deal with local strings or files or are way too complicated for me to go through at this point.

  1. Can you provide me a link to a good XML parser class (that is included in the Android SDK)
  2. Provide me with an example of its use.
  3. An example of how the feed would get fetched from the Internet (curl? or something internal?)
  4. (Bonus) Tips and hints on how this would be best achieved.

Thanks in advance.

+1  A: 

you can look the sources of android-rss. Maybe a good idea maybe not.

dfa
+2  A: 

here's a tutorial on this: http://www.helloandroid.com/node/110

Reflog
+1  A: 

I don't think that anything is included into SDK. Check this out http://code.google.com/p/android-feed-reader/ it uses ROME for parsing. ROME has JDOM dependancy

ROME does not work - see my answer.
drozzy
+3  A: 

I too am looking for something similar.

So far I've looked at these options:

Informa

From a quick glance this seems very cumbursome and unintuitive. The class names like:

ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

give little sense of what they are about and the use of lower case 'L' and upper case 'i' do not give much hope for the quality of rest of the codebase.

What is more of a problem however is a huge number of dependencies that this parser needs, making it highly unlikely that android will run it. At this point I am not going to even try it - and just assume that it won't work.

Rome

This does not work because of some wierd things that don't work on Dalvik here. See problem reports here and here.

Apache Feedparser

Apache Feedparser looks abandoned, as it is in the Dormant category on the Apache page. Furthermore it looks to be absolutely broken, at least for me. I tried to incorporate it into the project - and after importing ALL the dependencies it is borking on the httpclient from apache. It could be that Android does not support some of them.

In any case here is what the code for it looks like (actually looks pretty good):

FeedParser parser = FeedParserFactory.newFeedParser();
URL url = new URL("http://www.blah.com/feeds");
parser.parse( listener, url.OpenStream(), resource );

FeedParserListener listener = new DefaultFeedParserListener() {
        //this gives us the title of the actual feed/site
        public void onChannel( FeedParserState state,
                               String title,
                               String link,
                               String description ) throws FeedParserException {


        }

        //this gives us the individual item
        public void onItem( FeedParserState state,
                            String title,
                            String link,
                            String description,
                            String permalink ) throws FeedParserException {
        }

        //called to set the date on which the entry was created
        public void onCreated( FeedParserState state, Date date ) throws FeedParserException {

        }

    };

onChannel and onItem methods can be found in FeedParserListener doc. onCreated is support for Atom the time for entry created.

If only Java people did things in a more elegant way, like python's universal feed parser.

drozzy
+5  A: 

http://www.ibm.com/developerworks/opensource/library/x-android/index.html

This is a full article on the different ways of parsing rss on the Android platform. It also contains the source code of several rss 2.0 parser implementations.

fberger
+1  A: 

There's a Google Code project that fixes ROME so that it works on Android. The project is android-rome-feed-reader. If you're curious, it fixes ROME by repackaging ROME and java.beans under com.google.code.rome.android.repackaged.

There is an example project available too so you can try it yourself. I can't post the URL for the demo thanks to stackoverflow not allowing more than one hyperlink...

Ash Lux
+2  A: 

I have implemented a simple Android RSS reader over at my blog http://automateddeveloper.blogspot.com/ which just implements a custom RSS reader with SAX and pulls down required information.

The complete eclipse project is available for download there as a working RSS reader for Android

rhinds
Looks good. Thanks for sharing. Did you try it with ATOM?
drozzy
No, but good point! when I wrote the code, it was done for a specific problem, so I only set up the SAX parser to check for the RSS elements I needed.That said, if you look at the SAX code, it should be easily modified to handle the ATOM schema (handle <entry> like the <item> tag and update the domain Article object (to handle multiple links for example). If i get a chance I may have a look at updating it.
rhinds
A: 

I have a blog about parsing RSS on Android using ROME. http://w2davids.wordpress.com/android-rssatom-feeds-parsing-with-rome/