【发布时间】:2014-03-17 15:39:37
【问题描述】:
我正在尝试使用 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 提供的the xpath1.c example 工具来表达我的表达式,并得到相同的错误消息:
$ ./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 脚本,得到了相同的结果。
【问题讨论】:
标签: xpath libxml2 xml-libxml