Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Created January 25, 2018 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrochkind/a8344b1805badec8109b6f95c89a745b to your computer and use it in GitHub Desktop.
Save jrochkind/a8344b1805badec8109b6f95c89a745b to your computer and use it in GitHub Desktop.
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