mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
70 lines
1.1 KiB
Ruby
70 lines
1.1 KiB
Ruby
|
begin
|
||
|
require "xml/encoding-ja"
|
||
|
rescue LoadError
|
||
|
require "xmlencoding-ja"
|
||
|
if defined?(Kconv)
|
||
|
module XMLEncoding_ja
|
||
|
class SJISHandler
|
||
|
include Kconv
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
module RSS
|
||
|
|
||
|
class XMLParser < ::XML::Parser
|
||
|
|
||
|
include XML::Encoding_ja
|
||
|
|
||
|
def listener=(listener)
|
||
|
@listener = listener
|
||
|
end
|
||
|
|
||
|
def startElement(name, attrs)
|
||
|
@listener.tag_start(name, attrs)
|
||
|
end
|
||
|
|
||
|
def endElement(name)
|
||
|
@listener.tag_end(name)
|
||
|
end
|
||
|
|
||
|
def character(data)
|
||
|
@listener.text(data)
|
||
|
end
|
||
|
|
||
|
def xmlDecl(version, encoding, standalone)
|
||
|
@listener.xmldecl(version, encoding, standalone == 1)
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
class Parser < BaseParser
|
||
|
|
||
|
private
|
||
|
def _parse
|
||
|
begin
|
||
|
parser = XMLParser.new
|
||
|
parser.listener = @listener
|
||
|
parser.parse(@rss)
|
||
|
rescue XMLParserError => e
|
||
|
raise NotWellFormedError.new(parser.line){e.message}
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
class Listener < BaseListener
|
||
|
|
||
|
include ListenerMixin
|
||
|
|
||
|
def xmldecl(version, encoding, standalone)
|
||
|
super
|
||
|
# Encoding is converted to UTF-8 when XMLParser parses XML.
|
||
|
@encoding = 'UTF-8'
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
end
|