Ruby on rails Xpath 2.0-xmlXPathCompOpEval:未找到函数匹配项

Ruby on rails Xpath 2.0-xmlXPathCompOpEval:未找到函数匹配项,ruby-on-rails,ruby,xpath,nokogiri,mechanize,Ruby On Rails,Ruby,Xpath,Nokogiri,Mechanize,我在Rails项目中运行Xpath 2.0,并尝试使用它提供的matches()函数,如下所示: page = Mechanize.new.get('http://www.example.com').parser page.search("//a[matches(text(),'lagerfordon','i')]").first.text 这会引发以下错误: RuntimeError: xmlXPathCompOpEval: function matches not found 我做错了什

我在Rails项目中运行Xpath 2.0,并尝试使用它提供的
matches()
函数,如下所示:

page = Mechanize.new.get('http://www.example.com').parser
page.search("//a[matches(text(),'lagerfordon','i')]").first.text
这会引发以下错误:

RuntimeError: xmlXPathCompOpEval: function matches not found
我做错了什么?

Nokogiri(Mechanize的基础)使用支持XPath 1.0但不支持XPath 2.0的libxml,因此没有可用的
匹配的
函数

您可以使用以下函数进行区分大小写的匹配:

//a[contains(text(),'lagerfordon')]
为了进行不区分大小写的匹配,或者使用更复杂的正则表达式,您需要在Ruby中过滤Mechanize的结果,或者创建一个自定义XPath函数