Menu

Xpath condition node equals text bug

PFFan
2016-11-09
2016-11-29
  • PFFan

    PFFan - 2016-11-09

    The following xpath finds a node while it shouldn't. This happens with VTD-xml java 2.12 and 2.13, while v2.11 works fine.

    XML: <CONTACT><ID>10</ID></CONTACT>
    Xpath: //CONTACT[ID='1']/ID
    Result:10

    Java unit test:

    @Test
    public void testXpath() throws Exception {
        String xml = "<CONTACT><ID>10</ID></CONTACT>";
        String expression = "//CONTACT[ID='1']/ID";
        VTDGen p = new VTDGen();
        p.setDoc(xml.getBytes("UTF-8"));
        p.parse(false);
        VTDNav nav = p.getNav();
        AutoPilot pilot = new AutoPilot(nav);
        pilot.selectXPath(expression);
        int evalXPath = pilot.evalXPath();
        if (evalXPath != -1) {
            String readValue = nav.toNormalizedString(nav.getText());
            Assert.assertEquals("10", readValue);
            Assert.fail("evalXpath should have returned -1, but returned " + evalXPath);
        }
    }
    

    When running the unit test above we get java.lang.AssertionError: evalXpath should have returned -1, but returned 2.

    Does anyone know why this happens? Is this a known bug?

     
  • jimmy zhang

    jimmy zhang - 2016-11-29

    this is a bug that has been idnentified and corrected in 2.13.1... I am embarassed by it and almost committed ritual suicide...

     

Log in to post a comment.