Sunday, 12 January 2014

Fetching RSS Feed Data

 Fetching RSS Feed Data 

Hello Friends ,today i am going to demonstrate you how to get RSS Feed using ROME API.in this example i am going to show you feeds from my blogspot.jars required for implementing below code is ROME.jar ,jdom 1.1 jar,purl-org-content-0.3.jar.
 
ROME represents syndication feeds (RSS and Atom) as instances of the com.sun.syndication.synd.SyndFeed interface.

Sample Code:


package org.demo.rssfeed;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

public class RssDemo
{
    public static void main(String args[]) throws IOException, IllegalArgumentException, FeedException
    {
        //you can define url as per your requirement
         //URL url  = new URL("http://nisargpathak.blogspot.com/feeds/6414895901982451683/comments/default");
        URL url  = new URL("http://nisargpathak.blogspot.com/feeds/5437369693711411335/comments/default");
         XmlReader reader = null;
           
            try {
               
                reader = new XmlReader(url);
                SyndFeed feed = new SyndFeedInput().build(reader);
                System.out.println("Feed Title: "+ feed.getAuthor());
          
               for (Iterator i = feed.getEntries().iterator(); i.hasNext();)
               {
                  SyndEntry entry = (SyndEntry) i.next();
                  System.out.println(entry.getTitle());
                      }
                  } finally {
                      if (reader != null)
                          reader.close();
                  }
    }
 

}
Sample Output is given below:









For any query ping me on pathak.nisarg@yahoo.com
Thanks for reading
Regards

No comments:

Post a Comment

๐Ÿค– ๐…๐ˆ๐๐Ž๐๐’ ๐๐ซ๐ž๐š๐ค๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก: ๐€๐ ๐ž๐ง๐ญ๐ข๐œ ๐‹๐‹๐Œ ๐€๐ ๐ž๐ง๐ญ๐ฌ ๐“๐š๐ค๐ž ๐‚๐จ๐ง๐ญ๐ซ๐จ๐ฅ ๐จ๐Ÿ ๐˜๐จ๐ฎ๐ซ ๐‚๐ฅ๐จ๐ฎ๐ ๐‚๐จ๐ฌ๐ญ๐ฌ ๐ฐ...