简体   繁体   中英

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:

  1. Construct an InputStreamReader yourself from InputStream, passing "UTF-8" as encoding
  2. 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.

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