Document structure
Document element
The single outermost element that contains every other element in the document.
There is exactly one, always. A file containing two sibling elements at the top level is not a malformed document — it is not a document at all, and no parser will accept it. This is what defeats the common instinct to concatenate two XML files.
The root element's name is how most formats are recognised: urlset means a sitemap, feed means Atom, rss means RSS. Our own detection works this way, and so does most of the tooling you will meet.
- Defined in
- XML 1.0 §2.1
- Category
- Document structure
- Also written
- root element, top-level element
Shown, not asserted
All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
Two top-level elements is not a document.
document.xml <a/><b/>What the engine returns
Extra content at the end of the document (line 1)Neither is an empty file.
document.xml What the engine returns
Document is empty (line 1)
What catches people out
- Concatenating two XML files never produces a valid one. Wrap them in a new root, or process them separately.
- Comments and processing instructions may sit outside the root element; elements and text may not.
- The DOCTYPE, when present, must name this element — a mismatch is reported even by non-validating parsers.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsDocument is emptyWhat an empty or whitespace-only file reports.
- Parse errorsStart tag expectedThe message when the first thing found is not a start tag.
- FormatsXML sitemapurlset — a root element that names the format outright.
Related terms
- ElementThe unit of structure in XML: a start tag, its content, and a matching end tag — or a single self-closing tag when there is no content.
- PrologEverything in a document before the root element's start tag: the XML declaration, any comments or processing instructions, and the document type declaration.
- Well-formedA document that obeys XML's syntax rules: one root element, strictly nested tags, quoted attribute values, escaped markup characters.
- Document type declarationThe <!DOCTYPE root …> in the prolog that names the document's root element and points at, or contains, its markup declarations.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.