XML error · prolog
Unsupported encoding
The declaration names an encoding the parser cannot decode — a typo, a vendor-specific label, or a charset the build of libxml2 was not compiled with.
Unsupported encoding: UTF-9 (line 1)What it means
The XML declaration's encoding attribute names the character set the bytes are written in. The parser must decode the bytes before it can read a single tag, so an encoding it does not recognise stops it at line 1.
This is not the same as a mismatch between the declared and actual encoding. Here the label itself is unusable; a mismatch decodes successfully and produces mojibake or an invalid-character error later.
What usually causes it
- A typo in the declaration: UTF8 without the hyphen is a common one.
- A legacy or vendor charset name that never made it into the IANA registry.
- A generator that copies the platform's own encoding label rather than a registered one.
- A build of libxml2 compiled without iconv, which narrows the supported set considerably.
How to fix it
- Use a registered name, spelled exactly: UTF-8, UTF-16, ISO-8859-1, windows-1252.
- Prefer UTF-8 and re-encode at the source; every XML parser is required to support it.
- Omit the encoding attribute entirely if the document really is UTF-8 — that is the default.
- Confirm the bytes match the label after changing it, or you trade this error for a decoding one.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
Xerces (Java)
The encoding "UTF-9" is not supported.expat (Python)
unknown encoding: line 1, column 30.NET System.Xml
'UTF-9' is not a supported encoding name.
Before and after
Both snippets are re-checked by the test suite against the real parser: the first is confirmed to produce the exact error above, the second to parse cleanly.
<?xml version="1.0" encoding="UTF-9"?>
<root>x</root><?xml version="1.0" encoding="UTF-8"?>
<root>x</root>Where this bites most
Other XML errors
- Opening and ending tag mismatch
- Premature end of data in tag
- Extra content at the end of the document
- Unescaped ampersand (EntityRef: expecting ';')
- Entity is not defined
- Start tag expected
- XML declaration allowed only at the start of the document
- Unquoted attribute value (AttValue expected)
- Attribute redefined
- Attributes construct error (unterminated quote)
- Invalid element name
- Document is empty
- Sequence ']]>' not allowed in content
- Comment not terminated
- Detected an entity reference loop
- PCDATA invalid Char value (control character)
- Unescaped '<' in an attribute value
- Invalid numeric character reference
- Blank needed here
- Malformed declaration expecting version
- Unsupported XML version
- Processing instruction not terminated
- CData section not finished
- Error parsing attribute name
- Double hyphen within comment
- CharRef: invalid decimal value
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.