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

Empty element

An element with no content, written either as a self-closing tag or as a start tag immediately followed by its end tag.

The two spellings are exactly equivalent. `<x/>` and `<x></x>` produce the same element with the same (empty) content, and no consumer can tell which was written — canonicalization proves it by rewriting one into the other.

An empty element is not the same as an absent one. A schema that permits an element to be missing is saying something different from one that permits it to be empty, and the difference matters most in formats where an empty value means "explicitly nothing".

Defined in
XML 1.0 §3.1
Category
Document structure
Also written
self-closing tag, <x/>

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.

  • Both spellings produce an element with no child nodes.

    document.xml
    <x><y/><y></y></x>
    expression
    count(/x/y[not(node())])

    What the engine returns

    2
  • Canonical form picks one spelling, which is why signatures survive reserialization.

    document.xml
    <x><y/></x>

    What the engine returns

    c14n
    <x><y></y></x>
    

What catches people out

  • Self-closing is not optional in XML the way it is in HTML: <br> is an unclosed element, not an empty one.
  • Canonical XML always writes the expanded form. A byte comparison against a self-closing original will differ.
  • An empty element still has its attributes, and they are the usual reason to write one.

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.