How to extract data from an RSS feed in Rockets

Blog post

Author
Message

Rocket Man
Posts: 383
Posted on: 2013-01-25 14:12:04.000
RSS feeds are useful and great, but the XML structure they come in is rather unwieldy to read through and parse. newLISP has a great function called (parse-xml) that converts an XML tree into a list, but now you just have an unwieldy list. It's helpful to be able to extract only the data we want and put it in a simple nested list.

I've written a new function in Rockets that lets you do just that.

First, get the data from the RSS feed URL that you want:


(set 'feed-url " http://penny-arcade.com/feed";))
(set 'rss-result (xml-parse (get-url feed-url)))


Now, we want to extract the fields "title", "author", and "link" from that feed.


(set 'field-result (get-fields-from-rss rss-result '("title" "author" "link")))


(field-result) will return the following:


(("News Post: The Book Of Divine Wisdom" "tycho@penny-arcade.com (Tycho)" " http://penny-arcade.com/2013/01/25/the-book-of-divine-wisdom1";)
("News Post: So many games!" "gabe@penny-arcade.com (Gabe)" " http://penny-arcade.com/2013/01/25/so-many-games";)
...etc ... )


If a field isn't present in the RSS data, (field-result) will populate that part of the list with the "nil" value instead.

NOTE: Remove the spurious ";" characters in the example code here before running it

Happy RSSing!


Views: 5876