2004-01-27 22:46:13 -05:00
|
|
|
require "rexml/document"
|
|
|
|
require "rexml/streamlistener"
|
|
|
|
|
|
|
|
module RSS
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class REXMLParser < BaseParser
|
|
|
|
|
2005-11-23 08:35:11 -05:00
|
|
|
class << self
|
|
|
|
def listener
|
|
|
|
REXMLListener
|
|
|
|
end
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-11-23 08:35:11 -05:00
|
|
|
private
|
2004-10-16 00:51:15 -04:00
|
|
|
def _parse
|
|
|
|
begin
|
|
|
|
REXML::Document.parse_stream(@rss, @listener)
|
|
|
|
rescue RuntimeError => e
|
|
|
|
raise NotWellFormedError.new{e.message}
|
|
|
|
rescue REXML::ParseException => e
|
|
|
|
context = e.context
|
|
|
|
line = context[0] if context
|
|
|
|
raise NotWellFormedError.new(line){e.message}
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class REXMLListener < BaseListener
|
|
|
|
|
|
|
|
include REXML::StreamListener
|
|
|
|
include ListenerMixin
|
|
|
|
|
2005-11-23 08:35:11 -05:00
|
|
|
class << self
|
|
|
|
def raise_for_undefined_entity?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def xmldecl(version, encoding, standalone)
|
2004-11-19 03:25:25 -05:00
|
|
|
super(version, encoding, standalone == "yes")
|
2004-10-16 00:51:15 -04:00
|
|
|
# Encoding is converted to UTF-8 when REXML parse XML.
|
|
|
|
@encoding = 'UTF-8'
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method(:cdata, :text)
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
end
|