XML error reference · XV014
Encoding mismatch
The declared encoding does not match how the bytes actually decode.
What your parser calls it
The same problem, reported differently by each parser. If you arrived here from one of these strings, you are in the right place.
| Parser | Message |
|---|---|
| libxml2 / xmllint | Input is not proper UTF-8, indicate encoding ! |
| libxml2 / xmllint | switching encoding: encoder error |
| .NET XmlException | Invalid character in the given encoding. |
What causes it
The XML declaration is a claim about the bytes, not an instruction to convert them. If it says `encoding="ISO-8859-1"` but the file is really UTF-8, every multi-byte character is decoded as two or three wrong characters, producing the familiar "é" instead of "é". The reverse produces outright parse failures, because stray high bytes are not valid UTF-8 sequences. A byte order mark that contradicts the declaration is a related case.
See it happen
<?xml version="1.0" encoding="ISO-8859-1"?>
<name>José</name><?xml version="1.0" encoding="UTF-8"?>
<name>José</name>How to fix it
Decide which encoding the bytes really are and make the declaration agree. UTF-8 is the right answer for almost all new documents. Re-encode the file rather than only editing the declaration, otherwise you have simply moved the problem.
Fix your own document
Paste your own document below. Press Sample if you want the broken example above loaded instead. Nothing you paste leaves this tab.
XML Validator
Well-formedness and schema validation. Nothing is uploaded.
Everything runs in this tab. Nothing you paste is uploaded, logged or sent anywhere. Open your network panel and check.