XML error reference · XV013

Malformed XML declaration

The XML declaration is present but its syntax or attribute order is wrong.

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.

ParserMessage
libxml2 / xmllintMalformed declaration expecting version
Firefox DOMParserXML Parsing Error: XML declaration not well-formed

What causes it

The declaration has a fixed grammar: `version` is required and must come first, then optionally `encoding`, then optionally `standalone`. The pseudo-attributes must be lowercase, quoted and separated by whitespace, and `standalone` accepts only "yes" or "no". Reordering them or omitting the version is not permitted even though it looks harmless.

See it happen

Triggers the error
<?xml encoding="UTF-8" version="1.0"?>
<root/>
Corrected
<?xml version="1.0" encoding="UTF-8"?>
<root/>

How to fix it

Write the declaration as `<?xml version="1.0" encoding="UTF-8"?>`. If you do not need to state a non-default encoding the whole declaration is optional: a document with no declaration is assumed to be XML 1.0 in UTF-8.

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.

Input
WaitingPaste a document to check it. Validation runs as you type.

Everything runs in this tab. Nothing you paste is uploaded, logged or sent anywhere. Open your network panel and check.

Tools that catch this

Background reading

Errors this fixes

Every XML error, explained