XML Declaration Not at Start – Fix Declaration Position Errors
Local processing
When an XML declaration is present, it belongs at the beginning of the XML document rather than after the root element or ordinary content.
28 chars · 1 line
Waiting for input
Loading XML parser…
XML declaration troubleshooting
How to fix an XML declaration that is not at the start
The preloaded document puts <?xml version="1.0"?> after the root element. The XML declaration describes the document itself and, when used, must appear before the document element rather than as trailing processing content. This tool is free to use. No account or payment is required.
Last updated
What you can do here
XML well-formedness validation
Broken XML example preloaded
Corrected XML comparison
.xml file import
Browser parser feedback
Browser-local processing
How to use
Search the document for <?xml and confirm how many declarations are present.
Move the single required declaration to the beginning of the XML source.
Remove declarations copied from embedded fragments and validate the final combined document.
The XML declaration belongs to the document prolog
It can specify version and encoding information for the XML document, but it is not an ordinary processing instruction that can be inserted after the root element.
Concatenating complete XML files often creates this error
If multiple source files each include their own declaration, joining their raw text can leave later declarations in the middle of the combined document. Merge the data at the XML tree level instead of concatenating full files.
Misplaced XML declaration example
Move the XML declaration before the document element.
Invalid XML
<root/><?xml version="1.0"?>
Corrected XML
<?xml version="1.0"?><root/>
Common questions
Frequently asked questions
Is an XML declaration required?
No. Many XML documents are valid without one.
Where does the XML declaration go?
When present, it appears at the beginning of the XML document.
Can a document contain two XML declarations?
No. A later declaration usually indicates that complete XML fragments were concatenated incorrectly.