PageRenderTime 27ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/rexml/parsers/streamparser.rb

http://github.com/agross/netopenspace
Ruby | 46 lines | 42 code | 2 blank | 2 comment | 2 complexity | a05611742797b26b29afc6add088c1ca MD5 | raw file
 1module REXML
 2  module Parsers
 3    class StreamParser
 4      def initialize source, listener
 5        @listener = listener
 6        @parser = BaseParser.new( source )
 7      end
 8      
 9      def add_listener( listener )
10        @parser.add_listener( listener )
11      end
12      
13      def parse
14        # entity string
15        while true
16          event = @parser.pull
17          case event[0]
18          when :end_document
19            return
20          when :start_element
21            attrs = event[2].each do |n, v|
22              event[2][n] = @parser.unnormalize( v )
23            end
24            @listener.tag_start( event[1], attrs )
25          when :end_element
26            @listener.tag_end( event[1] )
27          when :text
28            normalized = @parser.unnormalize( event[1] )
29            @listener.text( normalized )
30          when :processing_instruction
31            @listener.instruction( *event[1,2] )
32          when :start_doctype
33            @listener.doctype( *event[1..-1] )
34          when :end_doctype
35            # FIXME: remove this condition for milestone:3.2
36            @listener.doctype_end if @listener.respond_to? :doctype_end
37          when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
38            @listener.send( event[0].to_s, *event[1..-1] )
39          when :entitydecl, :notationdecl
40            @listener.send( event[0].to_s, event[1..-1] )
41          end
42        end
43      end
44    end
45  end
46end