2009-10-23

How to stop SAX parse on libxml-ruby

Stop SAX parse

Does anybody know some stop method?




require 'rubygems'
require 'libxml'
include LibXML

class PostCallbacks
include XML::SaxParser::Callbacks

def on_start_element(element, attributes)
if /usr/ =~ element
p element
raise 'stop!'
end
end


end

parser = XML::SaxParser.file('test.xml')
parser.callbacks = PostCallbacks.new
begin
parser.parse
rescue
p 'hard stop'
end


It will return 1st <usr> then stop.

0 件のコメント:

BCM4321 on Latitude D430

At kernel 3 find wireless hardware lspci | grep -i wireless  check using current kernel module with PCI bus address lspci -vv -s 0c:...