Overview
Introduction
XML's strict syntax rules are exactly what make it reliable for machine-to-machine exchange, but that strictness also means one missing closing tag or one malformed attribute can break an entire parser downstream. This validator checks a document's well-formedness the same way a real XML parser would, and points you straight at the problem when it isn't.
It's the check to run before debugging why an API call, a config load, or a build step is failing on an XML file you were handed or generated.
What Is XML Validator?
An XML validator (in the well-formedness sense used here) confirms that a document follows XML's structural syntax: every element is properly opened and closed, elements are correctly nested without overlapping, attribute values are quoted, and there's exactly one root element.
This is distinct from schema validation against an XSD or DTD, which checks that specific elements, attributes, and their arrangement match a predefined contract. This tool focuses on the more fundamental question: is this XML at all?
How XML Validator Works
Your input is run through the same stack-based parser used by the Prettifier and Minifier: tags are tokenized, matched against an explicit stack as they open and close, and any mismatch, unclosed tag, or malformed attribute throws an error with the exact character position it occurred at.
That position is converted into a line and column number for display. If parsing succeeds, the resulting tree is walked once to compute element count, attribute count, and maximum nesting depth.
When To Use XML Validator
Use it when a downstream system rejects an XML document and you need to confirm whether the problem is syntax (this tool) or something schema- or business-logic-related (a different tool).
It's also useful as a quick sanity check after hand-editing a config file, before assuming a failure elsewhere in a pipeline is unrelated to a typo in the markup itself.
Often used alongside XML Prettifier, XML Minifier and XML Syntax Highlighter.
Features
Advantages
- Runs entirely client-side, so documents with real configuration or customer data never leave your browser.
- Reports the exact line and column of a syntax error instead of a generic failure message.
- Surfaces useful structural stats (element count, attribute count, depth) for valid documents.
- No size limit beyond what your browser can hold in memory.
Limitations
- Checks well-formedness only, not conformance to an XSD or DTD schema, and not namespace resolution.
- Doesn't validate character encoding declarations or DOCTYPE-specific entity definitions.
- Very large files (tens of megabytes) may be slow, since the whole document is held in memory while parsing.
Examples
Best Practices & Notes
Best Practices
- Validate XML immediately after hand-editing it, before debugging further downstream.
- Run this before a schema validator when you're not sure whether a failure is a basic syntax issue or a schema mismatch.
- Check the reported depth and element count after generating XML programmatically, as a quick sanity check that nothing was duplicated or truncated.
Developer Notes
This shares the exact parser used by the Prettifier and Minifier (`parseXmlDocument` in the XML category's `lib/xml-core.ts`), so all three tools agree on what counts as well-formed and report identical error positions for the same broken input. Stats are computed with a single tree walk (`collectXmlStats`) rather than during parsing, keeping the parser itself free of validation-specific bookkeeping.
XML Validator Use Cases
- Debugging why an API client rejects an XML response
- Sanity-checking a hand-edited config file before deploying it
- Confirming a programmatically generated XML document has the expected element count and depth
- Isolating a syntax error from a schema or business-logic error in a larger pipeline
Common Mistakes
- Assuming a document that validates here also conforms to a specific XSD or DTD schema, well-formedness and schema validity are different checks.
- Overlapping closing tags (`<a><b></a></b>`) instead of properly nesting them (`<a><b></b></a>`).
- Leaving an attribute value unquoted or quoted with mismatched quote characters.
Tips
- Use the reported line and column to jump straight to the offending character.
- Pair with the Prettifier once a document validates, to make its structure easier to review.
- Upload a `.xml` file directly instead of copy-pasting if the document is large.