module Nokogiri::XML::Searchable
def search(*args)
)
}.new
end
node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
def regex node_set, regex
Class.new {
node.search('.//title[regex(., "\w+")]', 'div.employee:regex("[0-9]+")'
appear anywhere in the argument list. For example:
arguments are ones that you pass in. Note that this class may
to the method will be the current matching NodeSet. Any other
implement the function you want to define. The first argument
defined. To define custom functions create a class and
Custom XPath functions and CSS pseudo-selectors may also be
node.search('.//address[@domestic=$value]', nil, {:value => 'Yes'})
appended to the namespace bindings. For example:
For XPath queries, a hash of variable bindings may also be
node.search('bike|tire', {'bike' => 'http://schwinn.com/'})
node.search('.//bike:tire', {'bike' => 'http://schwinn.com/'})
A hash of namespace bindings may be appended:
node.search("div.employee", ".//title")
Search this object for +paths+. +paths+ must be one or more XPath or CSS queries:
call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
##
def search(*args) paths, handler, ns, binds = extract_params(args) xpaths = paths.map(&:to_s).map do |path| (path =~ LOOKS_LIKE_XPATH) ? path : xpath_query_from_css_rule(path, ns) end.flatten.uniq xpath(*(xpaths + [ns, handler, binds].compact)) end