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

Spring Boot SSL configuration -Tomcat Server

Hi Friends hope you all are doing well. Today I am going to demonstrate about how to configure SSL in Spring boot web Application. Need o...