XML Validator
Says what is wrong with an XML document and where, then formats it the way you want it.
How XML Validation Works
What is XML Validation?
Well formedness and validity are two different things, and only the first is checked here. A well formed document obeys the grammar: every tag is closed by a matching one, attribute values are quoted, an ampersand is written as an entity, and there is exactly one root element.
Validity is the further question of whether a document matches a schema, a DTD, an XSD or a RELAX NG grammar. That needs the schema, which this tool does not ask for.
How to Use
- Paste the document. It is checked on every keystroke, so there is nothing to press.
- When it does not parse, the line is quoted back with a caret under the exact column, and nothing else on the page pretends to describe it.
- The indent buttons set the shape of the output, including Minified. Attributes can be sorted, comments dropped and whitespace collapsed.
- Structure shows the element tree, the counts and any namespaces the document declares.
What Gets Caught
| Mismatched tags | A closing tag naming something other than the tag it closes, and the line the open one is on |
| Bare characters | An & that is not an entity, or a < in an attribute value |
| Attributes | A value without quotes, a missing value, the same name twice on one tag |
| Namespaces | A prefix nobody declared, and a namespace that is not a URI |
| Document shape | A second root element, content outside the root, a DOCTYPE in the wrong place |
| Entities | Anything other than amp, lt, gt, quot and apos without a DOCTYPE |
Important Notes
- Only the first error is reported. XML gives a parser no reliable way to carry on afterwards, so a second message would be a guess.
- A document with a DOCTYPE may declare its own entities. Those are not read here, so any entity name is accepted once a DOCTYPE is present.
- Formatting rebuilds the document from the parsed tree. Whitespace between elements is not significant in most uses of XML, but it is in some, and collapsing it will change those documents.
- The output is the document as the parser understood it, so a numeric character reference comes back as the character it names.
Privacy & Security: the document is parsed in your browser. Nothing you paste is sent anywhere, and the tool works with the network disconnected.