Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created October 15, 2011 00:09
Show Gist options
  • Save mahemoff/1288737 to your computer and use it in GitHub Desktop.
Save mahemoff/1288737 to your computer and use it in GitHub Desktop.
# adapted from http://dekstop.de/weblog/2006/02/recursive_ruby_opml_parser/
# Returns a map from URL => text-field
require 'rexml/Document'
def parse_opml(opml)
if opml.is_a? String
doc = REXML::Document.new(opml)
opml = doc.elements['opml/body']
end
feeds = {}
opml.elements.each('outline') do |el|
if (el.elements.size != 0)
feeds.merge!(parse_opml(el))
end
if (el.attributes['xmlUrl'])
feeds[el.attributes['xmlUrl']] = el.attributes['text']
end
end
return feeds
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment