我正在尝试使用libxml 2.8.0 评估某些 XPath 表达式,并收到带有函数的错误消息。我不清楚 libxml 是实现 XPath 规范的全部还是一部分。是否有任何资源清楚地确定实现了什么以及如何使用它?
在我的具体情况下,我试图评估的一个表达式是:
/TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(./@actionA,'cook') and fn:exists(./IngredientA[fn:contains(./@classes,'onion')])])]
我通过 XML::LibXML Perl 模块使用 libxml,但我也尝试了使用 xmlsoft.org 提供的xpath1.c
示例工具的表达式,并得到了相同的错误消息:
$ ./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
我已经尝试过使用和不使用fn
命名空间,无论是使用xpath.c
Perl 脚本还是我的 Perl 脚本,都得到了相同的结果。