Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath 2.0 - xmlXPathCompOpEval: function matches not found

I am running Xpath 2.0 in my Rails project and tried to use the matches() function that it provides like so:

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

which throws the following error:

RuntimeError: xmlXPathCompOpEval: function matches not found

What am I doing wrong?

like image 657
Severin Avatar asked Sep 15 '14 12:09

Severin


1 Answers

Nokogiri (which Mechanize is built on) uses libxml which supports XPath 1.0, but not XPath 2.0, and so there is no matches function available.

You could do a case sensitive match using the contains function:

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

In order to do a case insensitive match, or to use a more complex regular expression, you will need to filter the result from Mechanize in Ruby, or create a custom XPath function.

like image 99
matt Avatar answered Nov 08 '22 11:11

matt