-
-
Save jrochkind/a8344b1805badec8109b6f95c89a745b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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