gpt4 book ai didi

java - Xpath 计算 "[ ]"中的计数

转载 作者:数据小太阳 更新时间:2023-10-29 02:09:03 25 4
gpt4 key购买 nike

我和成员们一起上课-

private Document myDoc;
XPath xpath = XPathFactory.newInstance().newXPath();

我尝试使用evaluate 函数 -

Object result = xpath.evaluate(expression, this.myDoc,
XPathConstants.NODESET);

expression 是一个 string s.t

expression = "inventory/book[" +
"count(following-sibling::book/price/text()=14.95)=0 ]" ;

我得到以下异常 -

java.lang.RuntimeException: Can not convert #BOOLEAN to a NodeList!

即使我将 XPathConstants.NODESET 更改为 XPathConstants.NUMBER,我也会遇到同样的异常。提前致谢。

最佳答案

这是 XPath 1.0 返回类型错误的少数情况之一:count() 函数的参数是一个 boolean 表达式 (path/a/b = 14.94),而 count() 要求它是一个节点-放。 (在 XPath 2.0 中,单个 boolean 值的计数为 1,因此您的查询将成功运行,并给出错误答案)。

关于java - Xpath 计算 "[ ]"中的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10699459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com