~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/rexml/parsers/streamparser.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module 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
 
46
end