Schemas and validity
Well-formed
A document that obeys XML's syntax rules: one root element, strictly nested tags, quoted attribute values, escaped markup characters.
Well-formedness is binary and non-negotiable. A document that fails it is not XML, and a conforming parser must report the error and stop rather than guessing — the specification calls this a fatal error, and it is the single biggest difference between XML and HTML.
It says nothing about whether the document is the right shape. A sitemap with no <loc> elements, an invoice missing every total, a feed whose dates are nonsense: all well-formed. That question is validity, and it needs a schema.
- Defined in
- XML 1.0 §2.1
- Category
- Schemas and validity
- Also written
- well-formedness
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.
Nonsense in the right syntax is well-formed.
document.xml <invoice><total>banana</total></invoice>What the engine returns
Well-formed.Correct-looking content in the wrong syntax is not.
document.xml <invoice><total>100</invoice></total>What the engine returns
Opening and ending tag mismatch: total line 1 and invoice (line 1)
What catches people out
- Namespace correctness is a separate specification. An undeclared prefix parses cleanly and is still wrong.
- Well-formedness errors are fatal by design. A parser that recovers from one is not conforming, however convenient that feels.
- Encoding problems surface as well-formedness errors, because the parser cannot read the characters at all.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- ToolsXML validatorAnswers exactly this question, and prints the parser's own message.
- Parse errorsOpening and ending tag mismatchThe most common way a document fails it.
Related terms
- ValidA well-formed document that also conforms to a declared grammar — a DTD, an XSD schema or a RELAX NG grammar.
- Document elementThe single outermost element that contains every other element in the document.
- ParserThe component that reads XML text and reports its structure to an application, or reports a fatal error and stops.
- Namespace prefixThe short NCName bound to a namespace URI by an xmlns:prefix declaration, used before a colon to qualify names.
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.