Class: REXML::PullParser

Class REXML::PullParser |
In: | rexml/pullparser.rb
Parent: | Object

# 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

empty? entity has_next? new next peek unshift

Included modules

XMLTokens

Public Class methods

new(stream)

Public Instance methods

empty?()

Returns true if there are no more events

has_next?()

Returns true if there are more events. Synonymous with !empty?

unshift(token)

Push an event back on the head of the stream. This method has (theoretically) infinite depth.

peek(depth=0)

Peek at the `depth` event in the stack. The first element on the stack is at depth 0. If `depth` is -1, will parse to the end of the input stream and return the last event, which is always :document_end. Be aware that this causes the stream to be parsed up to the `depth` event, so you can effectively pre-parse the entire document (pull the entire thing into memory) using this method.

next()

Returns the next event. This is a `PullEvent` object.

entity( reference )