Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'nokogiri'
ENTER_PROMPT = 'Running. Press <Enter> to pause.'
def ui
loop do
puts '(c)ontinue'
puts '(n)ext'
puts '(q)uit'
print '> '
case STDIN.gets.chop
when 'c'
puts ENTER_PROMPT
break
when 'n' then return true
when 'q' then exit
end
end
end
def listen_loop
puts ENTER_PROMPT
loop do
begin
STDIN.read_nonblock(1)
rescue Errno::EAGAIN
yield
else
break if ui
end
end
end
def mem_push_parser_document
html = <<END
<?xml version="1.0"?>
<!DOCTYPE staff SYSTEM "staff.dtd" [
<!ENTITY ent1 "es">
]>
<staff></staff>
END
doc = Nokogiri::XML::SAX::Document.new
listen_loop do
parser = Nokogiri::XML::SAX::PushParser.new(doc)
parser.write(html)
end
end
mem_push_parser_document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment