Quiz Entry - updated: 2026.06.23
What does it mean for an XML document to be "well-formed", and what are the core rules?
Well-formed means the tags follow XML's structural grammar — properly nested, one root, every start-tag closed — so any parser can read it without choking.
XML lets you invent tag names, but it is strict about how you write them. A document that breaks these rules is rejected outright by parsers (it won't even load), so "well-formed" is the minimum bar:
- One root element — exactly one top-level element wraps everything.
- Every element is closed — a start-tag
<m1>needs a matching end-tag</m1>(or the self-closing form<m1/>). - Proper nesting, never crossed —
<m1><m2></m2></m1>is fine;<m1><m2></m1></m2>is illegal because the tags overlap instead of nesting. - Case-sensitive —
<Name>and<name>are different elements and won't match each other. - Quoted attribute values —
id="123", notid=123. - Escape special characters — write
<for<and&for&, since the raw characters mean "tag" and "entity".
<!-- Illegal: tags cross over -->
<a><b></a></b>
<!-- Well-formed: b closes inside a -->
<a><b></b></a>
Tip: "Well-formed" only means the syntax is correct. Whether the document also matches a specific schema (the right elements in the right places) is a separate, stricter check called validity.