How to get bytes as UTF-8Y in Java
I am using a sax parser to parse the xml file which has an encoding of utf-8y. How can I specify that 开发者_运维技巧in the sax parser or the input source ? I always get a parse exception
I presume you're reading the file via an InputStream? The parser should be able to determine the file type from the XML header. If you read the file into a string, and then parse that the it tends to go pear-shaped
Just to make sure: is that 'Y' something that is included in 'encoding' value of XML document? Then I am not surprised you get an error -- there is no such encoding. I assume this is an error in whatever produced the document and should be fixed.
But on your side, you have two main options:
- Construct an InputStreamReader yourself from InputStream, passing "UTF-8" as encoding
- Modify input document before parsing to remove that 'y' from there
First approach is simple, and most parsers should be ok with it. Second option can be used if first doesn't work.
精彩评论