Home / Developer tools / XML validator

XML Validator

Check your XML for errors. Every problem is shown with its line and column and a marked line of code, and a summary of the structure appears when the XML is good.

Options

Result

Well-formed and valid are not the same

Two checks have the name validation. Well-formed means the document follows the syntax rules of XML: tags match, attributes have quotes, special characters are escaped, and there is one root element. Valid means it also follows a schema, such as an XSD or a DTD, which says which elements and attributes are allowed. This tool checks that your XML is well-formed. It does not check a schema. A document that is not well-formed cannot be read by any XML program, so this is the first check to pass.

What is checked

  • Every start tag has a matching end tag, in the right order, with the same name and case.
  • There is exactly one root element, and nothing but comments and whitespace outside it.
  • Attribute values are in quotes, and no attribute appears twice on an element.
  • Names follow the XML rules for the first character and the later characters.
  • The characters < and & are escaped in text, and every entity is either one of the five predefined ones, a valid number, or declared in the DOCTYPE.
  • Comments, CDATA sections and processing instructions are written correctly.
  • The XML declaration, when it is there, is at the very start and has a valid version, encoding and standalone value.
  • Every namespace prefix, such as dc: in dc:creator, is declared with xmlns:dc. You can turn this check off.
  • No characters that XML forbids, such as most control characters.

How errors are shown

XML parsers stop at the first serious error, because the rest of the document cannot be trusted after it. This tool keeps going where it can, so it lists problems that do not stop the reading, such as a duplicate attribute or a bare ampersand, together with the first error that does. Each one has its line and column, and the line of code is shown with a marker under the spot.

Common errors

MessageUsual cause
Closing tag does not matchA tag was not closed, or the case differs (<Name> and </name>).
Bare ampersandA text such as "Tom & Jerry" must be written Tom &amp; Jerry.
Attribute value must be in quotesid=42 instead of id="42".
Duplicate attributeThe same attribute appears twice in one tag.
Prefix is not declaredA name such as dc:title is used without xmlns:dc.
Text outside the root elementExtra text or a second root element after the first one closes.
XML declaration not at the startA space, a blank line or a byte before the declaration.

The summary

When the XML is well-formed you see the root element, the number of elements and attributes, the depth, the declared namespaces, and a table of the element names with how often each one is used and which attributes they carry. It helps you check that a file looks like you expect.

Fix bare ampersands

The most common error in hand-made XML is an unescaped &. A button replaces every bare ampersand with &amp;, outside of comments and CDATA sections, and checks the result again.

Check against a schema

To check against an XSD from the command line, use xmllint --noout --schema schema.xsd file.xml. For well-formedness alone, xmllint --noout file.xml does the same as this page.

When the XML is good, tidy it with the XML formatter or the XML beautifier, shrink it with the XML minifier, or convert it with XML to JSON. The XML syntax guide lists the rules, and the HTML entities guide explains character references.

Frequently asked questions

How do I validate XML online?

Paste your XML in the box. The tool tells you at once whether it is well-formed, and lists each error with its line and column.

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

Well-formed XML follows the syntax rules of XML. Valid XML also follows a schema or a DTD. This tool checks that it is well-formed.

Can this tool validate against an XSD schema?

No. It checks well-formedness only. For a schema check, use a command line tool such as xmllint.

Why does an ampersand break my XML?

The ampersand starts an entity in XML, so a bare one is an error. Write &amp; instead, or use the button that fixes it for you.