module XML::XXPathMethods
set of convenience wrappers around XML::XPath's instance methods, for people who frequently use XML::XPath directly. This module is included into the REXML node classes and adds methods to them that enable you to write a call like
path.first(xml_element)
as the more pleasant-looking variant
xml_element.first_xpath(path)
with the added bonus that path may not only be an XML::XXPath instance, but also just a String containing the XPath expression.
Please note that the names of all the added methods are suffixed with “_xpath” to avoid name clashes with REXML methods. Please note also that this was changed recently, so older versions of xml-mapping (version < 0.9) used method names without _xpath appended and thus would be incompatible with this one here.
As a special convenience, if you're using an older version of REXML that doesn't have the new methods yet, methods without _xpath in their names will also (additionally) be added to the REXML classes. This will enable code that relied on the old names to keep on working as long as REXML isn't updated, at which point that code will fail and must be changed to used the methods suffixed with _xpath.
Public Instance Methods
see XML::XXPath#all
# File lib/xml/xxpath_methods.rb, line 47 def all_xpath(path,options={}) to_xxpath(path).all self, options end
# File lib/xml/xxpath_methods.rb, line 52 def create_new_xpath(path) to_xxpath(path).create_new self end
see XML::XXPath#each
# File lib/xml/xxpath_methods.rb, line 37 def each_xpath(path,options={},&block) to_xxpath(path).each self, options, &block end
# File lib/xml/xxpath_methods.rb, line 42 def first_xpath(path,options={}) to_xxpath(path).first self, options end
# File lib/xml/xxpath_methods.rb, line 75 def to_xxpath(path) if String===path XXPath.new path else path end end