View RSS Feed

My Java Tips

Reading RSS using Informa API

Rate this Entry
by , 11-28-2011 at 06:56 PM (2176 Views)
RSS (Really Simple Syndication) is a family of Web feed formats used to publish frequently updated content such as blog entries, news headlines, and podcasts. It is actually a specification for XML files to provide syndicated data.


To read RSS feeds in a Java application is easy. You have to use Informa API which is availabel at:
http://informa.sourceforge.net/.

The code snippet given below shows how to read RSS using Informa API.

Java Code:
try {
  URL feed = new URL("file:/C:/samplefeed.rss");
  ChannelFormat format = FormatDetector.getFormat(feed);
  ChannelParserCollection parsers =
                          ChannelParserCollection.getInstance();

  ChannelParserIF parser =
    parsers.getParser(format, feed);

  parser.setBuilder(new ChannelBuilder());
  ChannelIF channel = parser.parse();

  for (Iterator iter = channel.getItems().iterator();
                                     iter.hasNext();) {
    ItemIF item = (ItemIF)iter.next();
    System.out.println(item.getTitle());
  }
} catch (MalformedURLException mue) {
  mue.printStackTrace();
} catch (UnsupportedFormatException ufe) {
  ufe.printStackTrace();
} catch (ParseException pe) {
  pe.printStackTrace();
}
This given example gets the RSS feed and prints out the news items on the console.

Submit "Reading RSS using Informa API" to Facebook Submit "Reading RSS using Informa API" to Digg Submit "Reading RSS using Informa API" to del.icio.us Submit "Reading RSS using Informa API" to StumbleUpon Submit "Reading RSS using Informa API" to Google

Tags: informa, rss Add / Edit Tags
Categories
Java EE

Comments