module Nokogiri::XML::Searchable
def xpath(*args)
node.xpath('.//title[nokogiri:regex(., "\w+")]', handler)
}.new
end
node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
def regex(node_set, regex)
handler = Class.new {
list. For example:
are ones that you pass in. Note that this class may appear anywhere in the argument
The first argument to the method will be the current matching NodeSet. Any other arguments
implement the function you want to define, which will be in the `nokogiri` namespace.
💡 Custom XPath functions may also be defined. To define custom functions create a class and
node.xpath('.//address[@domestic=$value]', nil, {:value => 'Yes'})
A hash of variable bindings may also be appended to the namespace bindings. For example:
node.xpath('.//xmlns:name', node.root.namespaces)
node.xpath('.//foo:name', {'foo' => 'http://example.org/'})
A hash of namespace bindings may be appended. For example:
node.xpath('.//title')
queries.
Search this node for XPath +paths+. +paths+ must be one or more XPath
xpath(*paths, [namespace-bindings, variable-bindings, custom-handler-class])
call-seq:
##
def xpath(*args) paths, handler, ns, binds = extract_params(args) xpath_internal(self, paths, handler, ns, binds) end