Well-Formedness Rules
A "well-formed" XML document is one that follows XML's syntax rules correctly. This is different from being "valid" (which means it matches a specific structure defined by a DTD or schema, covered next lesson) — well-formedness is the more basic bar every XML document has to clear just to be parsed at all.
Every tag needs a matching close
Unlike HTML, where a browser will forgive a missing closing tag, XML requires one for every element — or a self-closing tag for an element with no content:
<price>19.99</price> <empty-note />
The second form, <empty-note />, is shorthand for <empty-note></empty-note> — a self-closing tag for an element that has no content or children.
Proper nesting
Tags have to close in the reverse order they opened — they can't overlap:
<book><title>Dune</title></book>
<book><title>Dune</book></title>
In the second example, <title> opens inside <book> but closes after </book> already closed it — the tags cross over each other instead of nesting cleanly, and a parser rejects this outright.
Quoted attribute values
Attribute values must always be wrapped in quotes — single or double, but always something:
<book id="42"></book>
<book id=42></book>
Case sensitivity
XML tag names are case-sensitive, meaning <Item>, <item>, and <ITEM> are three completely different tag names as far as a parser is concerned:
<Item>Widget</item>
error: Opening and ending tag mismatch: Item line 1 and item
Even though Item and item look like the same word to a person, a parser treats the closing </item> as closing a tag that was never opened, since the actual open tag was <Item>, capital I.