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
2Canonical 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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsPremature end of data in tagWhat forgetting the slash produces, often many lines later.
- ToolsXML canonicalizer (C14N)Rewrites both spellings into the one canonical form.
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.
- Canonicalization (C14N)Rewriting a document into a single normal form — sorted attributes, expanded empty elements, resolved references, no declaration — so that equivalent documents become byte-identical.
- Content modelThe rule saying what an element may contain: which children, in what order, how many times, and whether text is allowed.
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.