XML error reference · XV012

Content before the XML declaration

Something appears before the XML declaration, which must be the very first thing in the document.

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
Java SAXParserContent is not allowed in prolog.
libxml2 / xmllintXML declaration allowed only at the start of the document
.NET XmlExceptionData at the root level is invalid. Line 1, position 1.
Python ElementTreeXML or text declaration not at start of entity: line 1, column 0

What causes it

If an XML declaration is present it must start at byte zero, with no whitespace, no blank line and no comment before it. In practice the invisible culprit is usually a UTF-8 byte order mark, or stray output from a script that echoed something before the XML. A leading blank line in a template file is the other classic.

See it happen

Triggers the error

<?xml version="1.0"?>
<root/>
Corrected
<?xml version="1.0"?>
<root/>

How to fix it

Remove whatever precedes the declaration. If nothing is visible, the file almost certainly starts with a byte order mark: re-save it as "UTF-8 without BOM", or strip the leading bytes EF BB BF. A BOM alone is tolerated by most parsers; a BOM plus a blank line is not.

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