Skip to content
DevToolKit

XML Validator

Validate XML well-formedness with line-number error pinpointing and structural analysis.

Waiting for Input

Paste or type XML to validate.

Uses the browser's native DOMParser API to check XML well-formedness. All processing happens locally in your browser.

XML Source
Was this tool helpful?

How to Use

Verify that your XML documents are syntactically correct before processing them in applications, APIs, or configuration systems.

  1. Paste XML: Enter your XML document into the editor panel. The validator runs automatically as you type.
  2. Check status: The status banner at the top shows green for well-formed XML or red with error details if the document is malformed.
  3. Review errors: If validation fails, the error panel in the sidebar displays the exact line number, column position, and a description of the parsing failure.
  4. View statistics: For valid documents, the statistics panel shows element count, attribute count, maximum nesting depth, and prolog details (version and encoding).
  5. Try samples: Click Valid Sample or Invalid Sample to load example XML documents that demonstrate correct syntax and common errors.

About This Tool

XML Well-Formedness Rules

XML well-formedness is a strict binary property defined by the W3C XML 1.0 specification (Fifth Edition, 2008). A document is either well-formed or it is not — there is no partial compliance. The parser must reject the entire document if any well-formedness constraint is violated. The core rules require exactly one root element, properly nested and matched opening/closing tags (XML is case-sensitive, so <Book> and <book> are different elements), quoted attribute values using either single or double quotes, and proper escaping of the five predefined entities: &amp;, &lt;, &gt;, &apos;, and &quot;.

XML vs HTML Parsing

HTML parsers are intentionally forgiving — they correct missing closing tags, handle unquoted attributes, and recover from syntax errors using the HTML5 error recovery algorithm. XML parsers have no such leniency. The XML specification explicitly mandates "fatal error" behavior: a conforming parser must stop processing and report the error when it encounters a well-formedness violation. This strict approach is by design — XML is used in data interchange (SOAP, RSS, SVG, XSLT, configuration files) where ambiguity in structure would cause downstream processing failures. This tool uses the browser's native DOMParser API with the application/xml MIME type, which enforces these strict parsing rules.

Common XML Errors and Fixes

The most frequent XML well-formedness errors fall into five categories. Unescaped ampersands in text content or attribute values: use &amp; instead of bare &. Mismatched tags due to case sensitivity: <Item> must close with </Item>, not </item>. Unquoted attribute values: write id="main" not id=main. Missing self-closing slash on empty elements: use <br/> not <br>. Multiple root elements: wrap siblings in a single parent element. Fixing these five patterns resolves over 90% of XML parsing failures in production systems.

Why Use This Tool

Private, Instant Validation

XML documents frequently contain sensitive configuration data — database connection strings, API endpoints, authentication tokens, and internal service URLs. This validator processes everything entirely in your browser using the native DOMParser API. No XML content is ever transmitted to any server, making it safe for validating production configurations, SOAP payloads with customer data, and internal deployment manifests.

The structural analysis panel provides immediate insight into your document's complexity — element count, attribute count, and maximum nesting depth. These metrics help identify overly complex XML structures that may cause performance issues in downstream parsers or exceed depth limits in security-hardened processing pipelines.

FAQ

What does XML well-formedness mean?
A well-formed XML document follows strict syntax rules: every opening tag has a matching closing tag, tags are properly nested, attribute values are quoted, the document has exactly one root element, and entity references use the five built-in entities or are declared in a DTD. Well-formedness is required before any XML parser can process the document.
What is the difference between well-formedness and schema validation?
Well-formedness checks that the XML follows basic syntax rules — proper nesting, quoted attributes, single root element. Schema validation (XSD, DTD, RelaxNG) goes further by verifying that the document's structure matches a predefined contract — specific element names, attribute types, cardinality, and data constraints. This tool checks well-formedness only.
How does DOMParser validate XML?
The browser's DOMParser API parses the XML string as application/xml. If the document is malformed, the parser returns a document containing a <parsererror> element with a description of what went wrong and where. This tool extracts line numbers, column positions, and error messages from that parsererror text.
What are the most common XML errors?
The five most common XML errors are: unclosed tags (<div> without </div>), mismatched tag names (<Div> closed with </div>), unescaped special characters (& instead of &amp;), missing quotes on attribute values (id=main instead of id="main"), and multiple root elements. All of these cause the parser to reject the document entirely.