Archive for the ‘rio’ Category

Ruby + OPML

Monday, August 28th, 2006

Ruby really is more productive. I wanted to add OPML support to a project of ours and from past .NET experience with this wasn’t looking all that forward to it. But rexml and rio came to the rescue.

Here is some sample Ruby code that extracts all the URLs from an OPML file:

opml_file = ''
rio('http://share.opml.org/opml/top100.opml') > opml_file
opml_doc = Document.new(opml_file)
urls = XPath.match(opml_doc, '//@xmlUrl')

That is it. rio does the hard work of saving the web-stored OPML file into a string. rexml does the hard job of parsing that string into an XML document and then we use XPath to find all of the xmlUrl attributes.

rexml comes with most standard Ruby installs and you can install rio with gem install rio. The rio documentation is here.