Validate XML
Check your XML for well-formedness and syntax errors. Get detailed statistics on elements, attributes, nesting depth, and file size.
Valid XML
Invalid XML
-
Elements
-
Attributes
-
Max Depth
-
Size
Well-Formedness vs. Validity
XML defines two distinct levels of correctness. A well-formed document obeys the fundamental syntax rules of the XML specification: every opening tag has a matching closing tag, attribute values are quoted, elements are properly nested, and there is exactly one root element. Any XML processor must reject a document that is not well-formed.
A valid document goes further: it is well-formed AND conforms to a schema - either a DTD (Document Type Definition) or an XSD (XML Schema Definition). Validity checking requires a schema file, which this tool does not require. This validator checks well-formedness only, which catches the vast majority of practical XML errors.
Well-Formedness Rules
- Single root element - the document must have exactly one top-level element containing all others.
- Matching tags - every start tag
<foo>must have a corresponding end tag</foo>, or be self-closed<foo/>. - Proper nesting - elements must be closed in reverse order of opening; overlapping tags like
<a><b></a></b>are illegal. - Quoted attributes - all attribute values must be enclosed in single or double quotes.
- Unique attributes - an element may not have two attributes with the same name.
- Escaped special characters - the characters
<and&in text content must be written as<and&.
Understanding the Statistics
Elements
The total count of all element nodes in the document tree, including the root. A document with many hundreds of elements may indicate a verbose schema that could benefit from a more compact representation like JSON or a binary format.
Attributes
The total number of attribute nodes across all elements. Attributes are metadata about an element (e.g. id, lang, type) and must be unique per element in well-formed XML.
Max Depth
The deepest nesting level in the document. Deeply nested XML (depth > 15-20) can stress recursive parsers and cause stack overflows in some environments. Flat XML is generally easier to query and transform.
Size
The UTF-8 byte size of the raw input. XML has significant overhead per element - typical XML payloads are 3-10x larger than equivalent JSON. For large documents, consider minification or a binary XML format like EXI.
Common Validation Errors
- Unclosed tags - the most frequent error; a missing
</tag>usually surfaces as a confusing error on a line far from the actual mistake. - Unescaped ampersands - writing
AT&Tinstead ofAT&Tin text content causes an immediate parse failure. - Case mismatch - XML is case-sensitive.
<Book>and</book>are different tags; mixing case is a well-formedness error. - Multiple root elements - pasting two XML documents together produces a document with two root elements, which is illegal. Wrap them in a container element.