Reading an ATOM feed using Rome and Java

Post to Twitter

Today I’ll show you how to read an ATOM feed using Rome with Java. I’m going to be using Atom Hopper as the ATOMPub server and you can check out my previous articles on how to get it running.

[ad name=”Google Adsense”]

With Atom Hopper up and running and assuming the database is clean (no entries), insert the following (very simplified) ATOM XML with Poster (you can find out how to use Poster in this article):

<?xml version="1.0"?>
<entry xmlns="">
  <title>Title 1</title>
  <content>Content for entry 1</content>
  <category term="Python" />
  <category term="Java" />

Note: Make sure if your using Poster to insert this ATOM XML you use an HTTP POST with the content type set to: application/atom+xml

I used Netbeans 7 to create a new Maven Java Application project. You only need to add one dependency to the POM which is: rome. Here is my entire POM.xml file:

<project xmlns="" xmlns:xsi=""





The code for the is as follows:

package com.giantflyingsaucer;

import com.sun.syndication.feed.synd.SyndCategoryImpl;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndLinkImpl;

import java.util.List;

public class App {

    public static void main(String[] args) {
        try {
            URL feedUrl = new URL("http://localhost:8080/namespace/feed/");

            SyndFeedInput input = new SyndFeedInput();
            SyndFeed feed = XmlReader(feedUrl));

            System.out.println("Feed Title: " + feed.getTitle());

            // Get the entry items...
            for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {               
                System.out.println("Title: " + entry.getTitle());
                System.out.println("Unique Identifier: " + entry.getUri());
                System.out.println("Updated Date: " + entry.getUpdatedDate());

                // Get the Links
                for (SyndLinkImpl link : (List<SyndLinkImpl>) entry.getLinks()) {
                    System.out.println("Link: " + link.getHref());

                // Get the Contents
                for (SyndContentImpl content : (List<SyndContentImpl>) entry.getContents()) {
                    System.out.println("Content: " + content.getValue());
                // Get the Categories
                for (SyndCategoryImpl category : (List<SyndCategoryImpl>) entry.getCategories()) {
                    System.out.println("Category: " + category.getName());
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());

Run the application and the results should be:

Feed Title: feed
Title: Title 1
Unique Identifier: urn:uuid:0fb3e0ec-ea46-4f13-9dc3-20df998e9d88
Updated Date: Thu Oct 13 18:01:48 CDT 2011
Content: Content for entry 1
Category: Python
Category: Java

Post to Twitter

This entry was posted in Atom Hopper, Java, Open Source. Bookmark the permalink.