2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2004-01-28 06:46:13 +03:00
|
|
|
require "rexml/document"
|
|
|
|
require "rexml/streamlistener"
|
|
|
|
|
|
|
|
module RSS
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class REXMLParser < BaseParser
|
|
|
|
|
2005-11-23 16:35:11 +03:00
|
|
|
class << self
|
|
|
|
def listener
|
|
|
|
REXMLListener
|
|
|
|
end
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2005-11-23 16:35:11 +03:00
|
|
|
private
|
2004-10-16 08: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-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class REXMLListener < BaseListener
|
|
|
|
|
|
|
|
include REXML::StreamListener
|
|
|
|
include ListenerMixin
|
|
|
|
|
2005-11-23 16:35:11 +03:00
|
|
|
class << self
|
|
|
|
def raise_for_undefined_entity?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def xmldecl(version, encoding, standalone)
|
2004-11-19 11:25:25 +03:00
|
|
|
super(version, encoding, standalone == "yes")
|
2004-10-16 08: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-28 06:46:13 +03:00
|
|
|
|
|
|
|
end
|