Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

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.

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.