Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Port to REXML.

  • Loading branch information...
commit db63950b3512be36b945a43428f57d95e3b037c5 1 parent 363ee25
@AustinBlues authored
Showing with 19 additions and 25 deletions.
  1. +4 −8 examples/opml_to_yaml.rb
  2. +15 −17 lib/opml_speed_reader.rb
View
12 examples/opml_to_yaml.rb
@@ -2,14 +2,10 @@
require '../lib/opml_speed_reader'
require 'yaml'
-
-# Disable noisy error reporting by libxml2 library on STDOUT
-XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
-
begin
- reader = XML::Reader.io(STDIN)
+ reader = REXML::Parsers::PullParser.new(STDIN)
puts OpmlSpeedReader.parse(reader).to_yaml
-rescue OpmlSpeedReader::NotOPML
- STDERR.puts "Not OPML"
- exit 1
+#rescue OpmlSpeedReader::NotOPML
+# STDERR.puts "Not OPML"
+# exit 1
end
View
32 lib/opml_speed_reader.rb
@@ -1,4 +1,5 @@
-require 'xml'
+#require 'xml'
+require 'rexml/parsers/pullparser'
require 'opml_speed_reader/version'
@@ -12,35 +13,32 @@ def self.parse(reader)
tag = nil # force scope
feed = {}
-
- while reader.read
- case reader.node_type
- when XML::Reader::TYPE_ELEMENT
- tag = reader.name
+
+ while reader.has_next?
+ event = reader.pull
+ case event.event_type
+ when :start_element
+ tag = event[0]
tag_stack.push(tag)
case tag_stack.join('>')
- when /opml>body(>outline)+/
- feed = {:title => reader['text'].strip}
- feed[:url] = reader['xmlUrl'].strip if reader['xmlUrl']
+ when /^opml>body(>outline)+$/
+ feed = {:title => event[1]['text'].strip}
+ feed[:url] = event[1]['xmlUrl'].strip if event[1]['xmlUrl']
if feed[:url].nil? # Category/folder start?
feed_stack.push([feed[:title]])
else
feed_stack[-1] << feed
feed = {}
end
- if reader.empty_element?
- tag_stack.pop
- end
end
- when XML::Reader::TYPE_TEXT, XML::Reader::TYPE_CDATA
+ when :text, :cdata
case tag_stack.join('>')
when 'opml>head>title'
- title = reader.value.strip
- feed_stack[0].unshift(title)
+ feed_stack[0].unshift(event[0])
end
- when XML::Reader::TYPE_END_ELEMENT
+ when :end_element
case tag_stack.join('>')
- when /opml>body(>outline)+/
+ when 'opml>body>outline'
tmp = feed_stack.pop
feed_stack[-1] << tmp
end
Please sign in to comment.
Something went wrong with that request. Please try again.