Skip to main content

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.

Fails
<?xml version="1.0" encoding="UTF-9"?>
<root>x</root>
Parses
<?xml version="1.0" encoding="UTF-8"?>
<root>x</root>

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.