java - Stax parser fails to read files with encoding UTF-16 -
i using stax parser read xml file inside common api in app. api takes inputstream parameter , doing below
public object <commonapi>(inputstream is) xmlinputfactory inputfactory = xmlinputfactory.newinstance(); xmleventreader reader = inputfactory.createxmleventreader(is); try{ while (parser.hasnext()) { xmlevent event = parser.nextevent(); // reaming parsing logic } } catch (exception e){ e.printstacktrace(); } }
the issue works if encoding in xml file utf-8. if utf-16, doesn't read properly..gives following exception
javax.xml.stream.xmlstreamexception: parseerror @ [row,col]:[1,41] message: content not allowed in prolog.
i can't change signature of common api. need operate on inputstream.. suggestions?
use createxmleventreader(inputstream stream, string encoding)
utf-16
encoding
.
Comments
Post a Comment