Well-formed and valid are different
XML has two levels of correctness. A document is well-formed when it follows the syntax rules: one root element, tags that match, quoted attributes, escaped special characters. A document is valid when it is well-formed and also obeys a schema, such as a DTD or an XSD, that says which elements and attributes are allowed.
This tool checks the first level. It will tell you whether the text is XML, not whether a particular program will accept it. For the second level, use a validator that has your schema.
What the checks cover
- Exactly one root element, and no text outside it.
- Every start tag has a matching end tag, in the right order and with the same capitals.
- Element and attribute names use only the characters XML allows.
- Attributes have a value in single or double quotes, and no name is repeated on one tag.
- No raw
<inside an attribute value, and no]]>in text. - Every
&starts a real entity: one of the five predefined names, a number such asA, or a name declared in the DOCTYPE. - Namespace prefixes are declared by an
xmlns:prefixattribute on the element or one of its parents. - Comments do not contain two hyphens in a row, and CDATA sections and processing instructions are closed.
- The XML declaration, if present, is the first thing in the document and is written in the right form.
- No control characters that XML 1.0 forbids.
Reading the report
Encoding label is the encoding value in the declaration. The text you paste is already decoded by the browser, so the label is not used to read it, but a program that reads the saved file will trust it. A warning appears if the label is not UTF-8, because that is the encoding of anything you copy or download from this page.
Nesting depth is how many elements are open at the deepest point. Namespaces lists each xmlns declaration it found. A DOCTYPE that points to an external DTD is noted, because entities and rules defined in it are not loaded.
Why an XML document is rejected
Browsers and XML libraries are strict on purpose: a document that is not well-formed is not partly read, it is refused. That is why one stray & in a long file can make the whole file fail in another program.
The messages here name the tag that is still open and the line where it began, so you can see where the nesting went wrong. If you are really looking at HTML, use the HTML formatter, which accepts unclosed tags. To lay out a document that already passes, use the XML formatter.