Parsing RSS feeds with J2ME and KXML

Some days have passed since last J2ME tutorial, so here is a fresh new one!

Today we’ll see how parsing a RSS feed with J2me is easy using KXML library, a fast and small XML pull parser, expecially suited for constrained environments like mobile devices. A live sample, parsing the RSS feed of this blog, is available here.

J2ME Kxml rss parser screenshot

The detailed explanation of source code is available on my Forum Nokia Wiki article: J2ME RSS Parser with KXml. If you’re interested only in plain source code, you can pick it up here (it includes also the sample midlet you find on the emulator page). To use KXmlRssParser class, you must simply do:

KXmlRssParser parser = new KXmlRssParser();
 
Vector rssItems = parser.parse(yourFeedURL);

and the parse() method will return the complete list of parsed Items, as instances of RssItem class. Source code is of course simplified, for the purpose of this tutorial, as it only considers title, link and description tags of each <item>, but once you understand KXml logic you can extend it, without much effort, to include other infos from RSS feed.

Other resources you might find useful:

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • Furl
  • Ma.gnolia
  • MisterWong
  • NewsVine
  • Reddit
  • StumbleUpon
  • Technorati

Tags: , , , ,

3 Responses to “Parsing RSS feeds with J2ME and KXML”

  1. J2ME, Flash Lite, Symbian, Iphone, Android and Ajax news, tutorials, source code » Blog Archive » How to parse a generic XML file in J2ME with kXML Says:

    [...] days ago I’ve posted J2ME code to parse RSS feeds using kXML library. Today’s code is about parsing a generic XML, so you can use it to parse [...]

  2. Mahesh Says:

    Hi i m a trainer in my comp, i saw the code its very nice n the standards are maintained i this coding. Currently i m working on xml parsing, so i juz want to know that if i want to display the names(channel names) in a list view on device, then is this the same procedure i need to follow or else there is a diferent way. If so can u plz tell me?

  3. Pit Says:

    Hi Mahesh,

    the approach and code described in this post works only to parse (and display) RSS feed items, but you can easily adapt it to parse channel names, or any other infos contained within the RSS feed.

    Pit

Leave a Reply