require 'rexml/parsers/pullparser' | |
def look_at_record(parser) | |
# While this first 'if' condition will never be triggered, it is somehow | |
# neccesary as is to trigger the core dump. | |
if Module.constants.index('FooBarBazNoSuchThing') && parser.is_a?(String) | |
else | |
while parser.has_next? | |
event = parser.pull | |
if event.end_element? | |
if event[0] == "record" | |
return "foo" | |
end | |
end | |
end | |
end | |
end | |
sample_xml = <<EOF | |
<record> | |
<leader>foo</leader> | |
</record> | |
EOF | |
parser = REXML::Parsers::PullParser.new(StringIO.new(sample_xml)) | |
while parser.has_next? | |
event = parser.pull | |
# if it's the start of a record element | |
if event.start_element? and event[0] == 'record' | |
puts look_at_record(parser) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment