Creating RSS using Java

I wanted to create RSS feeds for using Java. I did my ‘research‘, came to this page: Ben Java RSS libraries and then used the RSS4j library to create a servlet that serves up dynamic RSS feeds of the 10 most recently created recipes per category (samples: Breakfast, Soup, Barbeque..).

They syntax is pretty simple, you get an RssDocument and set which version you want to use (RSS 1.0, .9 or .91):

RssDocument doc = new RssDocument();

and then create a RssChannel object and add that to the RssDocument:

RssChannel channel = new RssChannel();
channel.setChannelTitle("Karens Recipes | Most Recent");
channel.setChannelDescription("The 10 most recently added recipes in the soup category.");

Next, you’ll retrieve the items using a database, the file system, etc… and add each item as a RssChannelItem:

// connect to the datasource
// iterate over something (db? vector?...)
RssChannelItem item = new RssChannelItem();

and then finally, using the RssGenerator class, call the generateRss() method, in this case I’m sending the output to a Servlet PrintWriter:

PrintWriter out = response.getWriter();
RssGenerator.generateRss(doc, out);

You could just as easily write it to a file:

File file = new File("/opt/data/rss.xml");
RssGenerator.generateRss(doc, file);
System.out.println("RSS file written.");
catch(RssGenerationException e){

Simple. Easy to use.

6 thoughts on “Creating RSS using Java”

  1. Does anyone have contact info for Jon Churchill, the author of rss4j? I’ve looked all over his site and through his downloads, and there is nothing to be found. So how can you suggest any improvements to his open source code?

    That said, this is a really nice little library, and I don’t want to fork my own version. I just need to be able to delete items from a channel. So items in RssChannel should be protected, or he should expose a remove method.

    Thanks, J

  2. ihad read the article it nice and very usefull for me because i am going to do the RSS project using j2se and XML, so i need key words for to start my project and books name please reply for this

  3. I read this article. This is very nice to me. I create RSS reader using java. WHat are the requirements? I have jdk1.2.0, Tomcat 5.0.
    I downloaded ur RSS4j.jar.
    Anythisng else need for create RSS reader

  4. Aaron, this is a very nice article.Please can you elaborate more clearly with the complete code and example?
    I will be eternally grateful


  5. churchillobjects.rss4j.generator.RssGenerationException: Invalid URI format: must be ‘http:’, ‘https:’, ‘ftp:’, or ‘mailto:’ – Link
    at churchillobjects.rss4j.generator.RssGenerator.validateUri(
    at churchillobjects.rss4j.generator.RssGeneratorImpl090.handleItemLink(
    at churchillobjects.rss4j.generator.RssGeneratorImpl100.handleDocumentItems(
    at churchillobjects.rss4j.generator.RssGeneratorImpl100.finishDocument(
    at churchillobjects.rss4j.generator.RssGenerator.writeRssDocument(
    at churchillobjects.rss4j.generator.RssGenerator.writeRssDocument(
    at churchillobjects.rss4j.generator.RssGenerator.generateRss(
    at com.soco.test.Test.main(

Leave a Reply

Your email address will not be published. Required fields are marked *