VTD-XML 2.11 Number of XPath () Expressions Failed Exception com.ximpleware.XPathEvalException: Expr function cannot be evaluated before node set

Using VTD-XML API 2.11 (Java), when evaluating an XPath expression count(//b)

in an XML document, <a><b/><b/></a>

instead of getting the result, 2.0

it fails with the following exception:

com.ximpleware.XPathEvalException:  Function Expr can't eval to node set
   at com.ximpleware.FuncExpr.evalNodeSet(FuncExpr.java:1033)
   at com.ximpleware.AutoPilot.evalXPath(AutoPilot.java:876)
   at ...testVTDXMLXPathFunctionCount(TestVTDXMLXPath.java:107)

      

Here's a very simple test case to reproduce the problem:

public void testVTDXMLXPathFunctionCount() throws Exception {
    AutoPilot autoPilot = new AutoPilot();
    try {
        VTDGen document = new VTDGen();
        document.setDoc("<a><b/><b/></a>".getBytes());
        document.parse(true);
        VTDNav navigator = document.getNav();
        autoPilot.selectXPath("count(//b)");
        autoPilot.bind(navigator);
        int j;
        while ((j = autoPilot.evalXPath()) != -1) {
            System.out.println(navigator.toNormalizedXPathString(j));
        }
    } catch (XPathParseException e) {
        e.printStackTrace();
    } catch (XPathEvalException e) {
        e.printStackTrace();
    } catch (NavException e) {
        e.printStackTrace();
    } finally {
        autoPilot.resetXPath();
    }
}

      

It looks like the count () function cannot be used as the start of an XPath expression with VTD-XML, even though this is a valid XPath 1.0 expression?

We greet you.

+3


source to share


1 answer


Try using evalXPathToNumber

instead selectXPath

.



+1


source







All Articles