Skip to main content

XML Validator

Check that your XML is well-formed and find the line where it is not

14
Loading editor…

Well-formed versus valid

Well-formed means the document follows XML's syntax rules, and that is what this page checks. Valid means it also conforms to a schema (an XSD or DTD) that lists which elements are allowed. Checking against a schema needs the schema file, which this tool does not take.

Because the browser's own parser does the work, the wording of an error depends on the browser you use.

Common XML errors and how to fix them

Each example below fails the well-formedness check.

Mismatched or unclosed tag

Invalid

<note>
  <to>Ada</from>
</note>

Fixed

<note>
  <to>Ada</to>
</note>

Every opening tag needs a closing tag with the same name and case, closed in reverse order of opening. <Note> and <note> are different tags.

Unescaped ampersand or less-than sign

Invalid

<title>Tom & Jerry</title>

Fixed

<title>Tom &amp; Jerry</title>

In text and attribute values, write & as &amp; and < as &lt;. A raw & starts an entity reference, so the parser expects a name and a semicolon after it.

Unquoted attribute value

Invalid

<book id=bk101>

Fixed

<book id="bk101">

Unlike HTML, XML requires quotes (single or double) around every attribute value.

More than one root element

Invalid

<a>1</a>
<b>2</b>

Fixed

<root>
  <a>1</a>
  <b>2</b>
</root>

A document has exactly one top-level element. Wrap the pieces in a parent element.

Whitespace before the XML declaration

Invalid


<?xml version="1.0"?>
<a/>

Fixed

<?xml version="1.0"?>
<a/>

If the document has an <?xml ...?> declaration, it must be the very first thing in it, with no blank line or space before it.

This validator checks that your XML is well-formed: tags match, attributes are quoted and special characters are escaped. It uses your browser's built-in XML parser, so the text is not sent anywhere.

Frequently Asked Questions

Does this validate against an XSD or DTD?

No. It checks that the XML is well-formed. Validating against a schema needs the schema file and a schema-aware validator.

Why does the error message look different in another browser?

The check uses the browser's built-in XML parser, and each browser words its errors differently.

Is my XML uploaded?

No. Parsing happens in your browser; the text never leaves your device.

Can I convert XML to JSON?

Yes. Once the XML is well-formed, use the XML to JSON converter to get the same data as JSON.

Have suggestions or feedback? We're constantly improving FormatChamp based on your comments.