Provides Tutorials on Web Technologies.

Feed4j Parser Reading RSS Feed

 

  • RSS  stands for  Rich Site Summary or Really Simple Syndication .
  • Feed4j.jar is a library for parsing RSS feeds.
  • This JAR file can be download from the following link:-
           http://www.sauronsoftware.it/projects/feed4j/download.php
  • There are 4 type of exception can be thrown while parsing RSS feed like FeedException, FeedIOException, FeedXMLParseException, UnsupportedFeedException.
          An additional parameters are added to this feed URL,
       
          max-results : Supply with some big number to retrieve all the post.
                            As of today my blog have around 55+  posts we are supplying a value of 1000.

         So the URL  is modified to (http://www.tutorialsavvy.com/feeds/posts/default?max-results=1000)

  • The Feed4j library is dependent on 4 other java libraries dom4j-1.6.1.jar , nekohtml.jar , xercesImpl.jar , xml-apis.jar .
  • The Project Structure is as below ,
       

  • The Java code for the feed parsing is TutorialSavvyRssFeedParser.java ,
package com.sandeep.blog.parser;

import it.sauronsoftware.feed4j.FeedIOException;
import it.sauronsoftware.feed4j.FeedParser;
import it.sauronsoftware.feed4j.FeedXMLParseException;
import it.sauronsoftware.feed4j.UnsupportedFeedException;
import it.sauronsoftware.feed4j.bean.Feed;
import it.sauronsoftware.feed4j.bean.FeedItem;
import java.net.MalformedURLException;
import java.net.URL;

public class TutorialSavvyRssFeedParser {

 public static void main(String[] args) {

  URL url = null;

  Feed feed = null;

  try {
   /*RSS URL For My Blog's Feed*/
   url = new URL("http://www.tutorialsavvy.com/feeds/posts/default?max-results=1000");

   feed = FeedParser.parse(url);

  } catch (MalformedURLException e) {
   e.printStackTrace();
  } catch (FeedIOException e) {
   e.printStackTrace();
  } catch (FeedXMLParseException e) {
   e.printStackTrace();
  } catch (UnsupportedFeedException e) {
   e.printStackTrace();
  }

  int items = feed.getItemCount();
  
  for (int i = 1; i <= items; i++) {
   
   FeedItem item = feed.getItem(i-1);
   
   System.out.println(i+" Title: " + item.getTitle());
   
  }

 }

}

Output:-

1 Title: Creating DataTable From RSS Feed And YQL
2 Title: YUI Chart Integration With Java
3 Title: Jquery SparkLine And DataTable Integration With Java
4 Title: CSS3 Rotation In X, Y, Z Axes
5 Title: CSS3 Transition
6 Title: YUI Asynchronous Data Table Load
7 Title: Asynchronous File Upload : Using YUI IO
8 Title: Ajax Queue For Servlet Using YUI IO
9 Title: YUI IO And Servlet Ajax Request
10 Title: Jsoup WhiteList : Sanitizing HTML Input
11 Title: CSS3 User Text Selection
12 Title: CSS3 : Multiple Backgrounds
13 Title: Aspect Ratio : Object Fit Property
14 Title: Safari Web Inspector Installation in Windows
15 Title: HTML Pseudo Elements And Classes
16 Title: Box Model in IE and FF
17 Title: Jquery DataTables And Java Integration
18 Title: Java Regular Expression : Matcher & Pattern
19 Title: Capacity & Load Factor : HashMap
20 Title: PostGre Admin 3 : Managing Database
21 Title: QDox Model : Java Source parsing
22 Title: Mongo Database Installation Windows XP(32 bit)
23 Title: Class World : Library for Managing Classes
24 Title: Rhino : JavaScript Library for Java
25 Title: NekoHtml : Document Fragment & Scanning
26 Title: Trove Collection : Procedure & Function
27 Title: Java NIO : performance Booster
28 Title: Google Guava Collections
29 Title: Quartz Scheduler :Scheduling Job in Java
30 Title: Object Comparison & Ordering in Java
31 Title: Convert String to Stream : Both Ways
32 Title: Apache Common Validator
33 Title: Jaxen Xpath Library With Dom4j
34 Title: Joda Time Library
35 Title: MD5 : Message Digest
36 Title: Apache Common Math Library
37 Title: JDOM :DOM parser
38 Title: JFreeChart In Servlet
39 Title: Apache Compression : Zip File
40 Title: QR : Quick Response Code
41 Title: Jaxb parsing : xml
42 Title: XStream Parser : XML & JSON
43 Title: Pretty Time Format :Java
44 Title: Json and Jquery Demo
45 Title: Escaping Html : Apache Common lang3
46 Title: Apache : PdfBox Api
47 Title: Java Logging
48 Title: Understanding JSON2.js
49 Title: JSON : What is JSON format
50 Title: Java : Null Pointer Exception
51 Title: Web Page Performance
52 Title: Garbage Collection in java
53 Title: Java Native Access (JNA)
54 Title: About Base 64 Encoding
55 Title: HTML 5 Canvas & JSON Demo
56 Title: Apache Poi Demo
57 Title: Servlet Dependency Injection : Guice Servlet
58 Title: Java Thread : Executor Service
59 Title: Oracle Object Type : Prepared Statement


Demo Code Download :- 

demo code download link 
Post a Comment