1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#!/usr/bin/env ruby
#
# Samizdat test suite utility methods
#
# Copyright (c) 2002-2011 Dmitry Borodaenko <angdraug@debian.org>
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU General Public License version 3 or later.
#
# vim: et sw=2 sts=2 ts=8 tw=0
require 'rexml/document'
require 'rexml/xpath'
XHTML_NS = { 'h' => 'http://www.w3.org/1999/xhtml' }
def elements(element, path, attribute=nil)
REXML::XPath.match(element, path, XHTML_NS).collect {|e|
attribute ? e.attributes[attribute] : e.text.strip
}
end
def text(element, path)
REXML::XPath.match(element, path, XHTML_NS).collect {|e|
e.texts.join.strip
}.join
end
def parse(html)
begin
doc = REXML::Document.new(html)
rescue REXML::ParseException
assert false, "REXML raised #{$!.class}: #{$!}"
end
doc.root
end
|