OPML-Parser
opml-parser is a simple Ruby gem that provides a module for parsing OPML.
Installation
gem install opml-parser
Usage
Import
subscriptions.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Foobar</title>
</head>
<body>
<outline text="foo" title="bar" type="rss" xmlUrl="http://www.gilliek.ch/feeds" htmlUrl="http://www.gilliek.ch"/>
</body>
</opml>
require 'opml-parser'
include OpmlParser
file = File.open("subscriptions.xml")
content = file.readlines.join("")
outlines = OpmlParser.import(content)
puts outlines[0].attributes
file.close
Output:
{:text=>"foo", :title=>"bar", :type=>"rss", :xmlUrl=>"http://www.gilliek.ch/feeds", :htmlUrl=>"http://www.gilliek.ch"}
Export
require 'opml-parser'
include OpmlParser
feed = {:text=>"foo", :title=>"bar", :type=>"rss",
:xmlUrl=>"http://www.gilliek.ch/feeds",
:htmlUrl=>"http://www.gilliek.ch"}
outline = OpmlParser::Outline.new(feed)
opml = OpmlParser.export([outline], "Foobar")
output = File.new("output.xml", "w")
output.puts(opml)
output.close
output.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Foobar</title>
</head>
<body>
<outline text="foo" title="bar" type="rss" xmlUrl="http://www.gilliek.ch/feeds" htmlUrl="http://www.gilliek.ch"/>
</body>
</opml>