English 中文(简体)
Xpath 评估“ []”中的 Xpath 评价计数
原标题:Xpath evaluate count in "[ ]"

我有与会员的等级 -

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

i 尝试使用 评价 函数 -

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

表达式 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 i, 也会得到相同的例外。 感谢提前。

最佳回答

尝试一下这个 :

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

这是 XPath 1.0 返回类型错误的少数例子之一: 计数 () 函数的参数是一个布林表达式( path/ a/b = 14.94), 和 count () 要求它是一个节点设置 。 (在 XPath 2.0 中, 单个布林的计数为 1, 所以您的查询会成功运行, 并给出错误的答案 ) 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签