Consuming RSS and Atom feeds
RSS feeds and Atom feeds are a standardized way to distribute headlines and updates from websites and blogs. Both RSS and Atom feeds are XML documents. RSS is older but widely popular, while Atom is newer and has several advantages over RSS, chiefly the namespace support.
For the main differences between Atom and RSS, check the Wikipedia entry about RSS: http://en.wikipedia.org/wiki/RSS. Both formats are largely supported, and often blogs and sites output headline feeds in RSS and Atom at the same time.
In this recipe, we are going to cover the basics of RSS and Atom feed parsing with Groovy.
Getting ready
As RSS and Atom feeds are XML based, it's easy to parse them using one of the several tools offered by Groovy (see the Reading XML using XmlParser recipe in Chapter 5, Working with XML in Groovy).
We will show how to detect if a feed is RSS or Atom and parse it accordingly.
How to do it...
We will create a FeedParser
class which will contain the code to open a URL...