XML error reference · XV003

More than one root element

The document contains a second top-level element. XML allows exactly one.

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 / xmllintExtra content at the end of the document
Firefox DOMParserXML Parsing Error: junk after document element
Python ElementTreejunk after document element: line 2, column 0
.NET XmlExceptionThere are multiple root elements.

What causes it

An XML document has a single document element that contains everything else. This trips people up when concatenating fragments, when a log appends records to a file without a wrapper, or when a database export writes one row element per line with no surrounding container. Each fragment is individually well-formed, but the file as a whole is not a valid XML document.

See it happen

Triggers the error
<record id="1"/>
<record id="2"/>
Corrected
<records>
  <record id="1"/>
  <record id="2"/>
</records>

How to fix it

Wrap the top-level elements in a single container element. If you genuinely need a stream of independent documents, use a framing format that carries them: one per line, a multipart body, or an archive. Do not concatenate them into one file.

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