Class: REXML::Parsers::BaseParser

Class REXML::Parsers::BaseParser |
In: | temp/parsers/baseparser.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 normalize peek pull stream= unnormalize unshift

Attributes

source | [R] |

Public Class methods

new( source )

Public Instance methods

stream=( source )

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 :end_document. 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.

pull()

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

entity( reference, entities )

normalize( input, entities=nil, entity_filter=nil )

Escapes all possible entities

unnormalize( string, entities=nil, filter=nil )

Unescapes all possible entities