Skip to content
codevory

XML Validator

Check that XML is well-formed and get the line and column of the first error, with a summary of elements, attributes and namespaces.

XML Validator: the tool

Paste XML to check that it is well-formed.

XML to check

Report

The validation report appears here.

How to use XML Validator

  1. Paste XML into the left panel, or press Example to load a document with two mistakes.
  2. If it is well-formed, the report lists the root element, the number of elements and attributes, nesting depth, namespaces and the declared version and encoding.
  3. If it is not, the status bar shows the line, the column and what is wrong. Press Go to error to jump to the position.
  4. Fix the first error and the next one, if any, appears. XML parsers stop at the first problem, and so does this tool.

Example

A catalog with an unescaped ampersand and a closing tag that does not match. The first problem is reported.

Input
<catalog>
  <book id="b1">
    <title>Networks & Protocols</title>
  </boo>
</catalog>
Result
Not well-formed · line 3, column 21: A bare '&' is not allowed. Write &amp; for an ampersand.
Report for a well-formed document
Result          Well-formed XML
Root element    <catalog>
Elements        3 (3 distinct names)
Attributes      1
Nesting depth   3
Text nodes      1
Comments        0
CDATA sections  0
Size            64 B as UTF-8

About this tool

A well-formed XML document follows the syntax rules that every parser enforces: one root element, properly nested and matching tags, quoted attribute values, unique attribute names, escaped special characters, and only characters that XML 1.0 allows. A document that breaks any of them is rejected completely, with no partial result, which is why a precise error position matters.

Messages explain the cause. A mismatch says which closing tag was expected, and on which line the open tag started. A bare ampersand points at the & and suggests &amp;. An undefined entity such as &nbsp; is reported, because XML predefines only five entities, unlike HTML.

This is a well-formedness check. The document is not validated against a DTD or an XML Schema (XSD), and namespace prefixes are not checked, so the report says so every time. Everything runs in your browser and nothing is uploaded.

Typical XML errors

ProblemExampleFix
Mismatched tag<a><b></a></b>Close elements in reverse order
Bare ampersand<a>Tom & Jerry</a>Write &amp;
Unquoted attribute<a id=1/>Write id="1"
Undefined entity<a>&nbsp;</a>Use &#160; or the character itself
Two root elements<a/><b/>Wrap them in one parent
Duplicate attribute<a x="1" x="2"/>Keep one

Frequently asked questions

What does well-formed mean?

That the document obeys XML's syntax rules, so any XML parser can read it. It does not mean that the content is correct for your application. That is what validity against a schema checks.

Does this validate against an XSD or DTD?

No. It checks well-formedness only, and the report reminds you of that. Use a schema-aware tool when you need to check structure and data types.

Why is &nbsp; an error?

XML predefines only &amp;, &lt;, &gt;, &quot; and &apos;. HTML entities such as &nbsp; or &copy; are unknown unless a DTD declares them. Use a numeric reference, for example &#160;.

Why does it report only one error?

XML parsers stop at the first fatal error, because after a syntax error the rest of the text cannot be interpreted reliably. Fix it and check again.

Does it accept the XML declaration and a BOM?

Yes. The declaration must be at the very start of the document, in lowercase, and a leading byte order mark is accepted.