insertAfterHead VTD 2.7

Help
2009-12-16
2013-05-15
  • Peter Anning
    Peter Anning
    2009-12-16

    When I try and use the insertAfterHead method of the XmlModifier when using xml with namespaces I get a  java.lang.ArrayIndexOutOfBoundsException<br/>

    <pre>
    package default;

    import java.io.ByteArrayOutputStream;

    import com.ximpleware.AutoPilot;
    import com.ximpleware.VTDGen;
    import com.ximpleware.VTDNav;
    import com.ximpleware.XMLModifier;

    public static void main(String arg) throws Exception{
    VTDGen generator = new VTDGen();
    generator.setDoc("&lt;tst:resp xmlns:tst='url'&gt;&lt;tst:level1&gt;&lt;/tst:level1&gt;&lt;/tst:resp&gt;".getBytes());
    generator.parse(true);
    VTDNav navigator = generator.getNav();
    AutoPilot autoPilot = new AutoPilot(navigator);
    autoPilot.declareXPathNameSpace("tst", "url");

    autoPilot.selectXPath("/tst:resp/tst:level1");
    // workaround use text() in Xpath
    //autoPilot.selectXPath("/tst:resp/tst:level1/text()");
    XMLModifier modifier = new XMLModifier(navigator);

    int i = -1;
    while((i=autoPilot.evalXPath())!=-1){
    modifier.insertAfterHead("&lt;test&gt;1&lt;/test&gt;");
    // workaround use updateToken with text() in Xpath
    //modifier.updateToken(i, "&lt;test&gt;1&lt;/test&gt;");
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    modifier.output(outputStream);

    System.out.println(outputStream.toString());
    }

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 196645
    at com.ximpleware.UniByteBuffer.byteAt(UniByteBuffer.java:42)
    at com.ximpleware.VTDNav.getCharUnit(VTDNav.java:854)
    at com.ximpleware.VTDNav.getOffsetAfterHead(VTDNav.java:1161)
    at com.ximpleware.XMLModifier.insertAfterHead(XMLModifier.java:854)
    at TestInsertAfterHead.main(TestInsertAfterHead.java:29)

        </pre>
    <br/>
        The workaorund is to use text() in the xpath to slect the text node then use update token to pass in the child element. Anybody else experiencing the same problem?
        <br/>Regards
       

     
  • jimmy zhang
    jimmy zhang
    2009-12-16

    will look into it and get back

     
  • jimmy zhang
    jimmy zhang
    2010-01-08

    the bug has been confirmed and the fix is already checked in…
    the official fix will go out in v2.8