class Automatic::OPML::Parser
Public Class Methods
new(port)
click to toggle source
# File lib/automatic/opml.rb, line 124 def initialize(port) @p = REXML::Parsers::PullParser.new(port) @opml = nil end
Public Instance Methods
each_outline() { |root, cur| ... }
click to toggle source
# File lib/automatic/opml.rb, line 174 def each_outline root = cur = nil while event=@p.pull case event.event_type when :xmldecl encoding = event[1] when :start_element case event[0] when "opml" root = cur = DOM::OPML.new when "head" e = DOM::Head.new cur << e cur = e when "body" e = DOM::Body.new cur << e cur = e when "outline" e = DOM::Outline.new # cur << e cur = e else cur['_' + event[0]] = read_text end event[1].each {|k,v| cur[k] = OPML::unnormalize(v) } if event[0]=="outline" yield root, cur end when :end_element cur = cur.parent if cur.kind_of? DOM::Element when :text when :cdata when :start_doctype when :end_doctype,:comment when :end_document break else p event.event_type p event raise "unknown event" end end # while end
parse_tree()
click to toggle source
# File lib/automatic/opml.rb, line 129 def parse_tree root = cur = nil while event=@p.pull case event.event_type when :xmldecl encoding = event[1] when :start_element case event[0] when "opml" root = cur = DOM::OPML.new when "head" e = DOM::Head.new cur << e cur = e when "body" e = DOM::Body.new cur << e cur = e when "outline" e = DOM::Outline.new cur << e cur = e else cur['.' + event[0]] = read_text end event[1].each {|k,v| cur[k] = OPML::unnormalize(v) } when :end_element cur = cur.parent when :text when :cdata when :start_doctype when :end_doctype,:comment when :end_document break else p event.event_type p event raise "unknown event" end end # while root end
read_text()
click to toggle source
# File lib/automatic/opml.rb, line 221 def read_text text = "" while event = @p.pull case event.event_type when :end_element break when :text text << OPML::unnormalize(event[0]) when :cdata text << event[0] else raise end end text end