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