Xerobit

XML Validator: Check Syntax and Well-Formedness

Paste your markup into this xml validator to check for syntax errors, mismatched tags and structural problems. It verifies that your document is well-formed according to the core XML specification. Everything runs locally in your browser, so your data is never uploaded to a server.

Paste the XML you want to validate.

Result

Valid XML. The document is well-formed.

How to use the xml validator

  1. Paste or type your XML markup into the text area.
  2. The xml validator checks the syntax automatically as you type.
  3. Review the result message below the input field.
  4. If an error is found, read the description to locate the problem.
  5. Fix the issue in your source file and paste it again to re-check.

What makes XML well-formed

A well-formed XML document follows a strict set of structural rules defined by the W3C XML 1.0 specification. Every opening tag must have a corresponding closing tag, or it must be explicitly self-closing with a trailing slash like <br />. Tags must nest properly without overlapping. For example, <a><b></a></b> is invalid because the b element crosses the boundary of the a element.

Attribute values must always be enclosed in single or double quotes. An attribute written as id=123 will cause a syntax error, while id="123" is correct. The document must also contain exactly one root element that wraps all other content. This xml validator checks all of these rules when you paste your markup.

How the validation works

This tool uses a lightweight tokenizer to scan your input character by character. It maintains a stack of open elements. When the parser encounters an opening tag like <book>, it pushes "book" onto the stack. When it finds a closing tag like </book>, it pops the top item off the stack and compares the names.

If the popped name does not match the closing tag name, the parser reports a mismatch. If the input ends while the stack still contains items, those tags were never closed. Self-closing tags such as <item /> are pushed and immediately popped, so they do not remain on the stack. The parser also tracks whether it is inside a quoted attribute value, a comment, a CDATA section or a processing instruction to avoid treating angle brackets inside those regions as markup.

Common XML syntax mistakes

Developers frequently run into a handful of recurring issues when writing XML by hand. Here are the most common ones:

  • Mismatched tags: A typo in the closing tag name, such as <user></usr>.
  • Missing closing tags: Forgetting to close an element before starting a sibling or ending the document.
  • Unquoted attributes: Writing <node count=5> instead of <node count="5">.
  • Multiple root elements: Placing two top-level elements side by side without a single parent wrapper.
  • Unescaped characters: Using raw ampersands (&) or angle brackets inside text content instead of their entity equivalents like &amp; or &lt;.

Catching these early saves time, especially when feeding files into parsers or APIs that reject malformed documents outright.

Well-formed versus valid XML

It is important to distinguish between well-formedness and validity. A well-formed document obeys the basic syntax rules of XML: proper nesting, quoted attributes, a single root and correctly formed tags. This xml validator focuses entirely on well-formedness.

Validity goes a step further. A valid XML document conforms to a specific schema, such as a DTD (Document Type Definition) or an XSD (XML Schema Definition). Schema validation checks whether the elements appear in the allowed order, whether required attributes are present and whether text content matches expected patterns. Because schema validation requires loading external definition files, it is typically handled by dedicated libraries or build tools rather than a quick client-side check.

Where XML is still used

Although JSON has become the default for many web APIs, XML remains deeply embedded in several domains. Configuration files for Java frameworks like Spring and Maven rely heavily on XML. SOAP web services use XML envelopes to structure requests and responses. Office document formats such as DOCX, XLSX and PPTX are actually ZIP archives containing multiple XML files.

RSS and Atom feeds, SVG graphics and SAML authentication assertions are all XML-based. In each of these contexts, a single syntax error can prevent the entire file from being parsed. Running your markup through an xml validator before deployment helps catch structural issues that might otherwise surface only in production logs.

If you also work with JSON, you may find the JSON formatter useful for structuring API responses, or the XML formatter to pretty-print your markup after validating it here.

Worked examples

Each result below was produced by the same code the tool runs, so you can check your own numbers against them.

ExampleInputResult
Valid documentXML input: <catalog> / <book id="1"> / <title>XML Basics</title> / </book> / </catalog>Valid XML. The document is well-formed.
Mismatched closing tagXML input: <root><child></chlid></root>Error: Mismatched closing tag. Expected </child>, found </chlid>
Missing quotes on attributeXML input: <item id=123 />Error in <item>: Unquoted attribute value

FAQ

Does this xml validator upload my data?

No. All parsing happens locally in your browser using JavaScript. Your XML is never sent to any server.

Can I validate against an XSD or DTD schema?

This tool checks for well-formedness only, meaning correct syntax, matching tags and proper nesting. Schema validation requires a dedicated processor that can load and interpret XSD or DTD definitions.

What is the difference between well-formed and valid XML?

Well-formed XML follows the basic syntax rules of the XML specification. Valid XML additionally conforms to a specific schema that defines allowed elements, attributes and their structure.

Why does my XML fail validation even though it looks correct?

Common hidden issues include unescaped ampersands in text content, missing quotes around attribute values or invisible whitespace characters. The error message from the validator usually points to the exact problem.

Does this tool support namespaces?

Yes. Tags with namespace prefixes like ns:element are treated as regular tag names. The validator checks that the opening and closing prefixed tags match exactly.

Can I check XML files larger than a few megabytes?

The parser processes text linearly, so it handles large inputs efficiently. However, extremely large files may cause the browser tab to slow down depending on your device memory.