Class: REXML::Parsers::PullParser
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Instance Chain:
self,
::REXML::XMLTokens
|
|
Inherits: | Object |
Defined in: | lib/rexml/parsers/pullparser.rb |
Overview
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 ::REXML::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.
Constant Summary
::REXML::XMLTokens
- Included
NAME, NAMECHAR, NAME_CHAR, NAME_START_CHAR, NAME_STR, NCNAME_STR, NMTOKEN, NMTOKENS, REFERENCE
Class Method Summary
- .new(stream) ⇒ PullParser constructor
Instance Attribute Summary
- #entity_expansion_limit=(limit) writeonly
- #entity_expansion_text_limit=(limit) writeonly
Instance Method Summary
Constructor Details
.new(stream) ⇒ PullParser
# File 'lib/rexml/parsers/pullparser.rb', line 38
def initialize stream @entities = {} @listeners = nil @parser = BaseParser.new( stream ) @my_stack = [] end
Instance Attribute Details
#entity_expansion_limit=(limit) (writeonly)
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 54
def entity_expansion_limit=( limit ) @parser.entity_expansion_limit = limit end
#entity_expansion_text_limit=(limit) (writeonly)
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 58
def entity_expansion_text_limit=( limit ) @parser.entity_expansion_text_limit = limit end
Instance Method Details
#add_listener(listener)
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 45
def add_listener( listener ) @listeners = [] unless @listeners @listeners << listener end
#each
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 62
def each while has_next? yield self.pull end end
#entity_expansion_count
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 50
def entity_expansion_count @parser.entity_expansion_count end
#peek(depth = 0)
[ GitHub ]#pull
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 78
def pull return @my_stack.shift if @my_stack.length > 0 event = @parser.pull case event[0] when :entitydecl @entities[ event[1] ] = event[2] unless event[2] =~ /PUBLIC|SYSTEM/ when :text unnormalized = @parser.unnormalize( event[1], @entities ) event << unnormalized end PullEvent.new( event ) end
#unshift(token)
[ GitHub ]# File 'lib/rexml/parsers/pullparser.rb', line 93
def unshift token @my_stack.unshift token end