0

I am using VTD-xml v2.11 and trying to get the contents of a tag using getContentFragment. When the xml has utf-8 encoding the code works fine. But for UTF-16 encoding the offset and len conversion is failing.

while ((i = ap.evalXPath()) != -1) {
        long l = vn.getContentFragment();
        if (l != -1) {
            int len = (int) (l >> 32);
            int offset = (int) l;
            sb.append(vn.toString(offset, len));
        }
    }

This works for UTF-8 xmls, but for UTF-16 it throws arrayindexoutofBound , when we call toString(offset,len) method. Could any please help to understand how to handle length and offset for UTF-16 encoded xml strings.

Thanks in advance...

Anil
  • 31
  • 4

1 Answers1

0

I think this might have been fixed in 2.13.1 version of vtd-xml. Can you download it and give it another try?

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30
  • Thank you for the suggestion, i will try this. meanwhile we were able to get around it by using offset/2 and len/2 in case of UTF-16. – Anil Apr 06 '17 at 20:55
  • Nice to know but I still suggest an upgrade to 2.13.1 – vtd-xml-author Apr 06 '17 at 21:05
  • I tried using 2.13.1 and the same code as listed above, but still receiving the Array index out of range error when encoding = UTF-16 is provided in the xml declaration. we set the bytes as UTF-16 when we have this declarion as utf-16 – Anil Apr 17 '17 at 16:56
  • Can you create a test case so I can dive into it a bit further? – vtd-xml-author Apr 17 '17 at 20:09
  • this is a bug with toString method.. will fix this in 2.13_2 – vtd-xml-author Apr 20 '17 at 01:20