Parse rss feed with XMLSlurper

In this example we will read an rss feed with Groovy's XmlSlurper. RSS or Really Simple Syndication is standard format used by website authors to share updated information such as blog entries, exercises, examples or tutorials. Most often consumers sign up for a service such as an RSS reader where you can register one to many feeds. Google reader used to be the powerhouse until it closed which made room for Feedly and Inoreader.

Pointing to level up lunches rss feed for groovy examples will loop through each item and print out the title, published date and url.

Parse lul groovy rss feed

@Test
public void parse_rss_xml_feed() {

    def rssFeed = "http://www.leveluplunch.com/feed/rss-groovy-examples.xml".toURL().text

    def rss = new XmlSlurper().parseText(rssFeed)
    rss.channel.item.each{
        println it.title
        println it.pubDate
        println it.link
        println "******"
    }
}

Output

******
This example will show how to make a get request to a URI in groovy with HttpBuilder. HTTPBuilder provides an abstraction on top of apache HttpComponents which provides a low level set of components for interaction with HTTP and associated protocols
Thu, 16 Oct 2014 20:23:32 -0500
http://www.leveluplunch.com/groovy/examples/make-get-request-httpbuilder-apache-httpcomponents/

******
Using groovy we will remove the first char in a string. We will use the phrase groovy and assert that each technique produces roovy using getAt, substring and subsequence
Mon, 13 Oct 2014 22:23:32 -0500
http://www.leveluplunch.com/groovy/examples/remove-first-character-from-string/

******