2003-06-09 21:31:01 -04:00
|
|
|
module REXML
|
|
|
|
module Parsers
|
|
|
|
class StreamParser
|
|
|
|
def initialize source, listener
|
|
|
|
@listener = listener
|
|
|
|
@parser = BaseParser.new( source )
|
|
|
|
end
|
|
|
|
|
2004-06-09 22:01:04 -04:00
|
|
|
def add_listener( listener )
|
|
|
|
@parser.add_listener( listener )
|
|
|
|
end
|
|
|
|
|
2003-06-09 21:31:01 -04:00
|
|
|
def parse
|
|
|
|
# entity string
|
|
|
|
while true
|
|
|
|
event = @parser.pull
|
|
|
|
case event[0]
|
|
|
|
when :end_document
|
|
|
|
return
|
|
|
|
when :start_element
|
2004-06-09 22:01:04 -04:00
|
|
|
attrs = event[2].each do |n, v|
|
|
|
|
event[2][n] = @parser.unnormalize( v )
|
|
|
|
end
|
|
|
|
@listener.tag_start( event[1], attrs )
|
2003-06-09 21:31:01 -04:00
|
|
|
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] )
|
2004-05-16 15:18:58 -04:00
|
|
|
when :start_doctype
|
|
|
|
@listener.doctype( *event[1..-1] )
|
|
|
|
when :notationdecl, :entitydecl, :elementdecl
|
|
|
|
@listener.notationdecl( event[1..-1] )
|
|
|
|
when :comment, :attlistdecl, :elementdecl, :cdata, :xmldecl
|
2003-06-09 21:31:01 -04:00
|
|
|
@listener.send( event[0].to_s, *event[1..-1] )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|