在libxml中使用XPath函数

在libxml中使用XPath函数,xpath,libxml2,xml-libxml,Xpath,Libxml2,Xml Libxml,我正在尝试使用2.8.0对某些XPath表达式求值,并在函数中得到错误消息。我不清楚libxml是实现了XPath规范的全部还是一个子集。是否有任何资源可以清楚地确定实施了什么以及如何使用 在我的具体案例中,我试图计算的一个表达式是: /TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(./@actionA,'cook') and fn:exists(./IngredientA

我正在尝试使用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提供的工具尝试了我的表达式,并得到了相同的错误消息:

$ ./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
$./xpath tester data/fk.xml//TemporalInformation/RecipeInformation[fn:exists(.>/ActionToActionRelation[fn:contains(./@actionA,'cook')和fn:exists(./@IngredientA[fn:contains(./@classes,'洋葱')])]”fn=http://www.w3.org/2005/xpath-functions"
xmlXPathCompOpEval:未找到函数包含
XPath错误:未注册的函数
xmlXPathCompOpEval:函数存在,未找到
XPath错误:未注册的函数
XPath错误:表达式无效
XPath错误:堆栈使用错误
错误:无法计算xpath表达式“/TemporalInformation/RecipeInformation[fn:exists(./ActionToActionRelation[fn:contains(../@actionA,'cook')和fn:exists(./Ingredenta[fn:contains(../@classes,'onion'))])”
用法:./xpath测试仪[]
其中是已知名称空间的列表
以“==href2>…”格式

我尝试了使用和不使用
fn
名称空间,都使用了
xpath.c
和我的Perl脚本,得到了相同的结果。

libxmlxpath实现仅为xpath 1.0,因此像
exists
这样的纯2.0函数不可用。在1.0中,您只有一些-有以开始的
,但没有以
结束的
,没有正则表达式支持,没有日期处理,等等。并且没有强类型,也没有像
if和的
这样的更高级别构造


所以要回答您的问题,是的,它确实支持整个XPath,但只支持XPath 1.0。

谢谢您提供的信息。因为它也为
包含
提供了一条错误消息,所以我没有发生这种情况。测试后,如果表达式未使用
存在,我确认
包含的错误消息将消失。真奇怪@scozy它会抱怨
fn:contains
,但不会抱怨
contains
没有
fn:
前缀。就XPath 1.0而言,
fn:contains
是一个未知的扩展函数,而不是核心函数。