1

I am trying to evaluate certain XPath expressions with libxml 2.8.0 and am getting error messages with functions. It is not clear to me whether libxml implements the whole or a subset of the XPath specification. Is there any resource clearly identifying what is implemented and how to use it?

In my specific case, one expression I am trying to evaluate is:

/TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(./@actionA,'cook') and fn:exists(./IngredientA[fn:contains(./@classes,'onion')])])]

I am using libxml through the XML::LibXML Perl module, but I have also tried my expression with the xpath1.c example tool available from xmlsoft.org, and got the same error messages:

$ ./xpath-tester data/fk.xml "/TemporalInformation/RecipeInformation[fn:exists(.> /ActionToActionRelation[fn:contains(./@actionA,'cook') and fn:exists(./IngredientA[fn:contains(./@classes,'onion')])])]" "fn=http://www.w3.org/2005/xpath-functions"
xmlXPathCompOpEval: function contains not found
XPath error : Unregistered function
xmlXPathCompOpEval: function exists not found
XPath error : Unregistered function
XPath error : Invalid expression
XPath error : Stack usage errror
Error: unable to evaluate xpath expression "/TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(./@actionA,'cook') and fn:exists(./IngredientA[fn:contains(./@classes,'onion')])])]"
Usage: ./xpath-tester <xml-file> <xpath-expr> [<known-ns-list>]
where <known-ns-list> is a list of known namespaces
in "<prefix1>=<href1> <prefix2>=href2> ..." format

I have tried with and without the fn namespace, both with xpath.c and my Perl script, and got the same result.

1 Answer 1

1

The libxml XPath implementation is only XPath 1.0, so 2.0-only functions such as exists aren't available. In 1.0 you only have a few core functions - there's starts-with but not ends-with, no regular expression support, no date handling, etc. and there's no strong typing and none of the higher-level constructs like if and for.

So to answer your question, yes, it does support the whole of XPath, but only XPath 1.0.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the information. Since it gave an error message for contains as well, this hadn't occured to me. After testing, I confirm the error message for contains disappears if the expression is not using exists. Strange enough!
@scozy it will complain about fn:contains but not about contains without the fn: prefix. As far as XPath 1.0 is concerned, fn:contains is an unknown extension function rather than a core function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.