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 件のコメント:
コメントを投稿