1

我正在尝试使用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.cPerl 脚本还是我的 Perl 脚本,都得到了相同的结果。

4

1 回答 1

1

XPath 实现只是 XPath 1.0,因此仅 2.0的libxml功能如exists不可用。在 1.0 中,您只有几个核心功能——starts-with但没有,没有正则表达式支持,没有日期处理等,没有强类型,也没有像andends-with这样的高级构造。iffor

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

于 2014-03-17T15:52:13.103 回答