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.
| Parser | Message |
|---|---|
| libxml2 / xmllint | Malformed declaration expecting version |
| Firefox DOMParser | XML 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
<?xml encoding="UTF-8" version="1.0"?>
<root/><?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.
Everything runs in this tab. Nothing you paste is uploaded, logged or sent anywhere. Open your network panel and check.