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

« back to all changes in this revision

Viewing changes to lib/rexml/parsers/ultralightparser.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
require 'rexml/parsers/streamparser'
 
2
require 'rexml/parsers/baseparser'
 
3
 
 
4
module REXML
 
5
        module Parsers
 
6
                class UltraLightParser
 
7
                        def initialize stream
 
8
                                @stream = stream
 
9
                                @parser = REXML::Parsers::BaseParser.new( stream )
 
10
                        end
 
11
 
 
12
      def add_listener( listener )
 
13
        @parser.add_listener( listener )
 
14
      end
 
15
 
 
16
      def rewind
 
17
        @stream.rewind
 
18
        @parser.stream = @stream
 
19
      end
 
20
 
 
21
                        def parse
 
22
                                root = context = []
 
23
                                while true
 
24
                                        event = @parser.pull
 
25
                                        case event[0]
 
26
                                        when :end_document
 
27
                                                break
 
28
                                        when :end_doctype
 
29
                                                context = context[1]
 
30
                                        when :start_element, :doctype
 
31
                                                context << event
 
32
                                                event[1,0] = [context]
 
33
                                                context = event
 
34
                                        when :end_element
 
35
                                                context = context[1]
 
36
                                        else
 
37
                                                context << event
 
38
                                        end
 
39
                                end
 
40
                                root
 
41
                        end
 
42
                end
 
43
 
 
44
                # An element is an array.  The array contains:
 
45
                #  0                    The parent element
 
46
                #  1                    The tag name
 
47
                #  2                    A hash of attributes
 
48
                #  3..-1        The child elements
 
49
                # An element is an array of size > 3
 
50
                # Text is a String
 
51
                # PIs are [ :processing_instruction, target, data ]
 
52
                # Comments are [ :comment, data ]
 
53
                # DocTypes are DocType structs
 
54
                # The root is an array with XMLDecls, Text, DocType, Array, Text
 
55
        end
 
56
end