Xpath evaluates score to "[]"

I have a class with members -

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

I am trying to use the evaluate function -

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

when expression is string st

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

and I get the following exception -

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

even when I change XPathConstants.NODESET to XPathConstants.NUMBER , I get the same exception. thanks in advance.

+4
source share
2 answers

Try the following:

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

This is one of the few cases where XPath 1.0 returns a type error: the argument to the count () function is a logical expression (path / a / b = 14.94), and count () requires it to be a node set. (In XPath 2.0, the number of one logical value is 1, so your request will be launched successfully and will give incorrect answers).

+2
source

Source: https://habr.com/ru/post/1413713/


All Articles