What Is Well-Formed XML? The 7 Rules (And How to Check)
"Well-formed" is XML's minimum bar: the syntax rules every XML document must satisfy before any parser will even read it. A sitemap, RSS feed or SOAP message that breaks one of these rules is not "XML with an error" — to a parser it is not XML at all. There are only seven rules.
Rule 1: exactly one root element
✓ <catalog><book/><book/></catalog>
✗ <book/><book/> <!-- two roots -->
Everything lives inside a single top-level element. (The <?xml ... ?> declaration and comments may sit outside it.)
Rule 2: every element is closed
✓ <name>Amina</name> ✓ <br/>
✗ <name>Amina <!-- never closed -->
Unlike HTML, XML has no optional closing tags and no void elements — an empty element must self-close with />.
Rule 3: elements nest properly
✓ <a><b>text</b></a>
✗ <a><b>text</a></b> <!-- crossed -->
The last element opened is the first one closed — strict stack discipline, no overlapping.
Rule 4: attribute values are quoted
✓ <price currency="GBP">9.99</price>
✗ <price currency=GBP>9.99</price>
Single or double quotes both work; absence of quotes never does. An element also cannot repeat the same attribute name.
Rule 5: reserved characters are escaped
✓ <url>page?a=1&b=2</url>
✗ <url>page?a=1&b=2</url>
The five entities: & < > " '. The raw ampersand in a URL is, by a wide margin, the most common well-formedness failure in real feeds and sitemaps.
Rule 6: tags are case-sensitive
✗ <Name>Amina</name> <!-- Name ≠ name -->
Rule 7: names follow the naming rules
Element and attribute names start with a letter or underscore — not a digit — contain no spaces, and cannot begin with the letters "xml" in any casing.
Well-formed vs valid — the distinction that matters
Well-formed = the syntax above is satisfied; any parser can read the document. Valid = additionally conforms to a specific schema (DTD/XSD) that defines which elements may appear where. Everyday breakage — the feed your reader rejects, the sitemap Search Console refuses — is almost always a well-formedness failure, not a schema one. Check well-formedness first, always.
How to check in seconds
Paste the document into our free XML validator: it parses with the browser's own strict XML parser and reports the first violation with its line number, then re-indents the corrected document. Nothing is uploaded — safe for private feeds and internal configuration. For the JSON equivalent of this rulebook, see JSON syntax rules explained.