2004-03-21 12:20:47 +03:00
|
|
|
begin
|
2004-10-16 08:51:15 +04:00
|
|
|
require "xml/parser"
|
2004-03-21 12:20:47 +03:00
|
|
|
rescue LoadError
|
2004-10-16 08:51:15 +04:00
|
|
|
require "xmlparser"
|
2004-03-21 12:20:47 +03:00
|
|
|
end
|
|
|
|
|
2004-01-28 06:46:13 +03:00
|
|
|
begin
|
2004-10-16 08:51:15 +04:00
|
|
|
require "xml/encoding-ja"
|
2004-01-28 06:46:13 +03:00
|
|
|
rescue LoadError
|
2004-10-16 08:51:15 +04:00
|
|
|
require "xmlencoding-ja"
|
|
|
|
if defined?(Kconv)
|
|
|
|
module XMLEncoding_ja
|
|
|
|
class SJISHandler
|
|
|
|
include Kconv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
end
|
|
|
|
|
2004-04-07 07:36:38 +04:00
|
|
|
module XML
|
2004-10-16 08:51:15 +04:00
|
|
|
class Parser
|
|
|
|
unless defined?(Error)
|
2014-01-19 09:43:26 +04:00
|
|
|
# This error is legacy, so we just set it to the new one
|
2013-08-19 21:02:40 +04:00
|
|
|
Error = ::XMLParserError # :nodoc:
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
|
|
|
end
|
2004-04-07 07:36:38 +04:00
|
|
|
end
|
|
|
|
|
2004-01-28 06:46:13 +03:00
|
|
|
module RSS
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class REXMLLikeXMLParser < ::XML::Parser
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
include ::XML::Encoding_ja
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def listener=(listener)
|
|
|
|
@listener = listener
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def startElement(name, attrs)
|
|
|
|
@listener.tag_start(name, attrs)
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def endElement(name)
|
|
|
|
@listener.tag_end(name)
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def character(data)
|
|
|
|
@listener.text(data)
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def xmlDecl(version, encoding, standalone)
|
|
|
|
@listener.xmldecl(version, encoding, standalone == 1)
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def processingInstruction(target, content)
|
|
|
|
@listener.instruction(target, content)
|
|
|
|
end
|
2004-03-21 12:20:47 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
class XMLParserParser < BaseParser
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2005-11-23 16:35:11 +03:00
|
|
|
class << self
|
|
|
|
def listener
|
|
|
|
XMLParserListener
|
|
|
|
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
|
|
|
|
parser = REXMLLikeXMLParser.new
|
|
|
|
parser.listener = @listener
|
|
|
|
parser.parse(@rss)
|
|
|
|
rescue ::XML::Parser::Error => e
|
|
|
|
raise NotWellFormedError.new(parser.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 XMLParserListener < BaseListener
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
include ListenerMixin
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
def xmldecl(version, encoding, standalone)
|
|
|
|
super
|
|
|
|
# Encoding is converted to UTF-8 when XMLParser parses XML.
|
|
|
|
@encoding = 'UTF-8'
|
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
2004-10-16 08:51:15 +04:00
|
|
|
end
|
2004-01-28 06:46:13 +03:00
|
|
|
|
|
|
|
end
|