Skip to content

Instantly share code, notes, and snippets.

@ender672
Created December 12, 2011 19:13
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 ender672/1468631 to your computer and use it in GitHub Desktop.
Save ender672/1468631 to your computer and use it in GitHub Desktop.
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