Well-formed XML: the rules that break most often
From the W3C XML 1.0 specification:
- Exactly one root element wraps everything.
- Every start tag has a matching end tag (or is self-closing,
<br/>), and tags close in the right order. - Tag names are case-sensitive:
<Item>…</item>is an error. - Attribute values are quoted, and an attribute appears only once per element.
&and<inside text must be written as&and<(or wrapped in CDATA).- The
<?xml …?>declaration, if present, must be the very first thing in the file.
Well-formed is not the same as valid
This tool checks well-formedness (the syntax). Checking against a schema (XSD or DTD) is a separate step.
Formatting and whitespace
Pretty-printing removes whitespace-only text between elements and trims text content. That is fine for data files and configs, but in mixed content (like XHTML paragraphs) whitespace can matter, so keep the original if exact spacing is important.
Sources
- W3C: Extensible Markup Language (XML) 1.0: www.w3.org/TR/xml/