XML Validator

Check whether your XML is well-formed. If it isn't, you get the line and column of the first error and a plain-English explanation of how to fix it.

Updated
Runs in your browser. Your data is not uploaded.
Checks as you type for inputs up to 200 KB.

How to use the XML Validator

  1. Paste XML into XML input, or upload or drop an .xml file.
  2. The XML is checked as you type. Press Validate to check it again at any time.
  3. If it is valid, read the document statistics. If not, the message shows the line and column, the line itself with a ^ under the problem, and how to fix it.

How it works

The validator reads the XML with a strict parser that follows the XML 1.0 well-formedness rules:

  • There is exactly one root element.
  • Every start tag has a matching end tag with the same name and case, and elements close in the reverse order they opened.
  • Attribute values are quoted, and no attribute appears twice on one element.
  • < and & in text are escaped as &lt; and &amp;, and every entity is one of the five predefined ones, a numeric reference, or declared in the DOCTYPE.
  • Names start with a letter, _, or :, and the XML declaration, if present, comes first.

Examples

  • <note><to>Ada</note> is invalid: the end tag </note> doesn't match the open element <to>. Fix: close <to> first.
  • <a href=https://example.com></a> is invalid: attribute values must be in quotes.
  • <q>Tom & Jerry</q> is invalid: a bare & must be written &amp;.
  • <a/><b/> is invalid: an XML document can have only one root element.
  • <list><item n="1"/><item n="2"/></list> is valid: 3 elements, 2 attributes, depth 2.

Limitations

  • This is a well-formedness check. Validation against a DTD, XSD, or RELAX NG schema isn't done, so a document with the wrong elements can still pass.
  • Only the first error is reported, because one mistake often causes others further down.
  • Entities declared in an external DTD file can't be resolved and are reported as warnings.
  • Files are limited to 5 MB.

Frequently asked questions

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

Well-formed XML follows the syntax rules: matched tags, quoted attributes, one root. Valid XML is also well-formed and matches a schema (DTD or XSD) that says which elements are allowed where. This tool checks well-formedness.

Why is my HTML reported as invalid XML?

HTML allows unclosed tags such as <br> and attributes without values. XML doesn't. Write <br/> and give every attribute a quoted value.

How do I include &, < or > in XML text?

Write &amp;, &lt;, and &gt;, or put the text in a CDATA section: <![CDATA[ a < b && c ]]>.

Is my XML uploaded?

No. It is checked in your browser.

Often used together with the XML Validator.

  • XML Formatter

    Beautifies XML with clean indentation or minifies it to one line.

  • JSON Validator

    Checks JSON syntax and explains any error in plain English.