Can VTD-XML take a string as input?

Hey, I'm trying to use VTD-XML to parse the XML provided to him as a String, but I cannot find how to do this. Any help would be appreciated.

http://vtd-xml.sourceforge.net

+4
source share
2 answers

The VTD-XML library seems to read byte array data. In this case, I would suggest converting the string to bytes using the correct encoding.

If encoding is specified at the beginning of the XML string:

<?xml version="1.0" encoding="UTF-8"?> 

Then use this:

 myString.getBytes("UTF-8") 

If the encoding does not exist, use it so that VTD-XML can decode bytes:

 String withHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + myString; byte[] bytes = withHeader.getBytes("UTF-8"); VTDGen vg = new VTDGen(); vg.setDoc(bytes); vg.parse(true); 

Please note that in a later case, you can use any valid encoding, because the string you have in memory is encoding-agnostic (this is in UTF-16, but when you ask for bytes to be converted).

+5
source

VTD-XML does not accept a string because the string implies UCS-16 encoding, which means that it is not an xml document .. as specified by the specification, xml is usually encoded in utf-8, ascii, iso-8859-1 or UTF-16LE or BE ... does my answer make sense?

+2
source

Source: https://habr.com/ru/post/1302123/


All Articles