Xpath 2.0 - xmlXPathCompOpEval: no function matches found

I am running Xpath 2.0 in a Rails project and trying to use the function matches()that it provides like this:

page = Mechanize.new.get('http://www.example.com').parser
page.search("//a[matches(text(),'lagerfordon','i')]").first.text

which causes the following error:

RuntimeError: xmlXPathCompOpEval: function matches not found

What am I doing wrong?

+4
source share
1 answer

Nokogiri (on which the Engine is built) uses libxml, which supports XPath 1.0 but not XPath 2.0, and therefore there is no function matches.

Using the function, containsyou can match the case:

//a[contains(text(),'lagerfordon')]

, Mechanize Ruby XPath.

+5

All Articles