简体   繁体   中英

Parsing ContentFragment using VTDXML for UTF-16 encoded xml

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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM