Home > Software design >  how can (Java) XPath return a number?
how can (Java) XPath return a number?

Time:10-17

My XPath is just /html/body/count(hr). I want to count the number of XHTML horizontal rules. This is for a test assertion, so if the number changes I want the assertion diagnostic text to reflect the number.

But xpath.compile(xpathExpression) throws "javax.xml.transform.TransformerException: Unknown nodetype: count"

El Goog says that an XPath expression can return a number; so can (Java's) XPath mechanics access it?


also this must fit inside an Android tablet's tests, so I can't use any third party XML parser that would destabilize my build. Saxon could do it

CodePudding user response:

You need a count of the tags at that path. The path is /html/body/hr.

count() is a function, not a tag or part of a path. So count() cannot come after /html/body/ because then it's looking for a count tag, and probably doesn't know what the () is.

So try:

count(/html/body/hr)
  • Related