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.
| Parser | Message |
|---|---|
| Java SAXParser | Content is not allowed in prolog. |
| libxml2 / xmllint | XML declaration allowed only at the start of the document |
| .NET XmlException | Data at the root level is invalid. Line 1, position 1. |
| Python ElementTree | XML 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
<?xml version="1.0"?>
<root/><?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.
Everything runs in this tab. Nothing you paste is uploaded, logged or sent anywhere. Open your network panel and check.