Created
December 12, 2011 19:13
-
-
Save ender672/1468631 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 '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