REXML::Parsers::PullParser (Class)

In: rexml/parsers/pullparser.rb
Parent: BaseParser

Using the Pull Parser

This API is experimental, and subject to change.

 parser = PullParser.new( "<a>text<b att='val'/>txet</a>" )
 while parser.has_next?
   res = parser.next
   puts res[1]['att'] if res.start_tag? and res[0] == 'b'
 end

See the PullEvent class for information on the content of the results. The data is identical to the arguments passed for the various events to the StreamListener API.

Notice that:

 parser = PullParser.new( "<a>BAD DOCUMENT" )
 while parser.has_next?
   res = parser.next
   raise res[1] if res.error?
 end

Nat Price gave me some good ideas for the API.

Methods

each   new   peek   pull  

Included Modules

XMLTokens

Public Class methods

[Source]

# File rexml/parsers/pullparser.rb, line 29
                        def initialize stream
                                super
                                @entities = {}
                        end

Public Instance methods

[Source]

# File rexml/parsers/pullparser.rb, line 34
                        def each
                                while has_next?
                                        yield self.pull
                                end
                        end

[Source]

# File rexml/parsers/pullparser.rb, line 40
                        def peek depth=0
                                PullEvent.new(super)
                        end

[Source]

# File rexml/parsers/pullparser.rb, line 44
                        def pull
                                event = super
                                case event[0]
                                when :entitydecl
                                        @entities[ event[1] ] = 
                                                event[2] unless event[2] =~ /PUBLIC|SYSTEM/
                                when :text
                                        unnormalized = unnormalize( event[1], @entities )
                                        event << unnormalized
                                end
                                PullEvent.new( event )
                        end

[Validate]