Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aggregating RSS Items in Java

I'm trying to build a polling service in Java that checks for updates from a RSS feed.

On detecting new items, it should only send new items further on in the system.

Is there an API that does this or would I have to do the comparison checks myself?

At the moment, my poller just returns what it currently sees causing duplicates in my system.


1 Answers

Sun have an RSS Utilities library that was built for creating feeds. However it also includes a useful RSS parser that I am using to do a similar thing.

You can download the library from here (scroll down to the bottom for more information on the parser):

http://java.sun.com/developer/technicalArticles/javaserverpages/rss_utilities/

To check for new items, just get the GUID and compare it with GUIDs for existing items.

// Create an RSS Parser
RssParser parser = RssParserFactory.createDefault();

// Parse the feed
Rss rss = parser.parse( new URL( YOUR_FEED ) );

// Get the channel
Channel channel = rss.getChannel();

// Get the items
Collection<Item> items = channel.getItems();

// Loop for each item
for ( Item item : items )
{
  // Get the GUID
  Guid guid = item.getGuid();

  // Loop for each of the previously seen GUIDs and compare
}
like image 141
Matthew Blackford Avatar answered Apr 01 '26 11:04

Matthew Blackford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!