1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/rexml/parsers/streamparser.rb
kou 75a138732e * lib/rexml/parsers/streamparser.rb
(REXML::Parsers::StreamParser#parse): Add "entity" event support to
  listener. [Bug #8689] [ruby-dev:47542]
  Reported by Ippei Obayashi.
* test/rexml/test_stream.rb (StreamTester#entity): Add a test for
  the above case.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-26 14:17:24 +00:00

50 lines
1.5 KiB
Ruby

module REXML
module Parsers
class StreamParser
def initialize source, listener
@listener = listener
@parser = BaseParser.new( source )
end
def add_listener( listener )
@parser.add_listener( listener )
end
def parse
# entity string
while true
event = @parser.pull
case event[0]
when :end_document
return
when :start_element
attrs = event[2].each do |n, v|
event[2][n] = @parser.unnormalize( v )
end
@listener.tag_start( event[1], attrs )
when :end_element
@listener.tag_end( event[1] )
when :text
normalized = @parser.unnormalize( event[1] )
@listener.text( normalized )
when :processing_instruction
@listener.instruction( *event[1,2] )
when :start_doctype
@listener.doctype( *event[1..-1] )
when :end_doctype
# FIXME: remove this condition for milestone:3.2
@listener.doctype_end if @listener.respond_to? :doctype_end
when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
@listener.send( event[0].to_s, *event[1..-1] )
when :entitydecl, :notationdecl
@listener.send( event[0].to_s, event[1..-1] )
when :externalentity
entity_reference = event[1]
content = entity_reference.gsub(/\A%|;\z/, "")
@listener.entity(content)
end
end
end
end
end
end