Micru Logo

Validate XML

Check your XML for well-formedness and syntax errors. Get detailed statistics on elements, attributes, nesting depth, and file size.

All processing is done locally in your browser. No data is sent to our servers.

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

  1. Single root element - the document must have exactly one top-level element containing all others.
  2. Matching tags - every start tag <foo> must have a corresponding end tag </foo>, or be self-closed <foo/>.
  3. Proper nesting - elements must be closed in reverse order of opening; overlapping tags like <a><b></a></b> are illegal.
  4. Quoted attributes - all attribute values must be enclosed in single or double quotes.
  5. Unique attributes - an element may not have two attributes with the same name.
  6. Escaped special characters - the characters < and & in text content must be written as &lt; and &amp;.

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&T instead of AT&amp;T in 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.