Document structure
Element
The 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.
Elements nest strictly and never overlap. That single rule is most of what well-formedness means, and it is the one HTML habits break: a start tag opened inside a sibling must be closed inside it too.
An element's name is a QName, so it carries a namespace as well as a local name. Two elements written with identical tag text are different elements if the namespaces in scope differ.
- Defined in
- XML 1.0 §3
- Category
- Document structure
- Also written
- tag, node
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.
Overlapping elements cannot form a tree, so the parser stops.
document.xml <a><b></a></b>What the engine returns
Opening and ending tag mismatch: b line 1 and a (line 1)Element children are selected by name; text and comments are not elements.
document.xml <r>text<a/><!-- c --><b/></r>expression count(/r/*)What the engine returns
2
What catches people out
- Element names are case-sensitive. <Item> and <item> are different elements, and closing one with the other is an error.
- There is no void element in XML. <br> must be written <br/> or closed explicitly.
- Order between siblings is part of the document; a schema that declares a sequence enforces it.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsOpening and ending tag mismatchWhat overlapping or unclosed elements report.
- Parse errorsExtra content at the end of the documentThe mirror image: an end tag with nothing open.
- Schema errorsThis element is not expectedThe validation failure when an element is well-formed but in the wrong place.
Related terms
- AttributeA name–value pair on an element's start tag, whose value is always a quoted string.
- Document elementThe single outermost element that contains every other element in the document.
- Empty elementAn element with no content, written either as a self-closing tag or as a start tag immediately followed by its end tag.
- Content modelThe rule saying what an element may contain: which children, in what order, how many times, and whether text is allowed.
- QNameA qualified name: an optional namespace prefix, a colon, and a local name — the form every element and attribute name takes in a namespaced document.
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.