java - Explanation of JAXB error: Invalid byte 1 of 1-byte UTF-8 sequence -


We are parsing an XML document using JAXB and get this error:

  [org .xml.sax.SAXParseException :. Invalid byte of 1-byte UTF-8 sequence 1] javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException at (AbstractUnmarshallerImpl.java:315)  

What exactly does and how do we Can this solve ??

We are implementing the code as:

  jaxbContext = JAXBContext.newInstance (Results.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller (); Unmarshaller.setSchema (getSchema ()); Result = (results) unmarshaller.unmarshal (new FileInputStream (inputFile)); The problem appears due to this "strange" character in the XML file:  ¿ 

update

/ code>

Why is such a problem caused ??

Update 2

There are two odd letters in the file. They are in the middle of the file, note that the file is built on the basis of the data in the database and those weird characters get in the database in any way.

Update 3

Here is the full XML snippet:

  & lt; Details & gt; & Lt ;! [CDATA [Mt. Belvieu ¿Texas]] & gt; & Lt; / Details & gt;  

Update 4

Note that someone & lt ;? Xml ...? & Gt; is not a header.

Hex BF

For the special character, then your problem is that JAXB behaves without XML files and & lt ;? Xml ... & gt; UTF-8, when your file uses some other encoding (probably ISO-8859-1 or Windows-1252, if the header 0xBF character actually means ¿).

You can change the file's creator, you can add & lt ;? Xml ... & gt; Write a file using the header with the actual encoding specification, or just use UTF-8 for the bus.

If you can not change the manufacturer, then you have to use InputStreamReader with a clear coding specification, because (unfortunately) JAXB does not allow to change its default Is encoding:

  result = (results) unmarshaller.unmarshal (new InputStreamReader (new FileInputStream (inputfile), "ISO-8859-1");  

However, this solution is delicate - it fails on input files with & lt;?. Xml ... & gt; Header with different encoding specification


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -