Help

XML Validator

Paste XML and this validator checks that it is well-formed, then shows the exact line and column of the first error in plain words. Add an XSD schema to check the structure too, and a valid document comes back pretty-printed. It runs in your browser, so the XML is not uploaded.


How to validate XML

  1. Press Paste XML to read the clipboard into the XML box, or paste into the box by hand. Pasting checks the document at once.
  2. Press Validate to check it again after you edit the text.
  3. Read the result under the button. A green Valid XML box means the document is well-formed. A red Not well-formed XML box shows one error.
  4. For an error, the box gives Line N, column M, a snippet of that line with a caret under the column, and a Show in editor button. The editor also scrolls to the line.
  5. Fix the first error and check again. Only the first error is shown on purpose: the ones after it are usually side effects of it, such as a missing end tag.

Pasting is the only way in, as there is no file picker. Open the file in any text editor, copy everything and paste it into the box.

What well-formed XML means

The first check is only about syntax. A document is well-formed when it follows these rules:

Well-formed is not the same as valid. Valid means the document also follows a schema, which is what the XSD option below is for.

Common XML errors and how to fix them

Each error is explained in a sentence rather than as a raw parser message. These are the ones people run into most:

What the validator saysUsual causeFix
The closing tag </a> does not match the open tag <b> from line 1A closing tag is missing, misspelled or in the wrong orderClose the tags in reverse order of opening
The document ends before <x> (opened on line N) is closedThe last end tag is missing, or the paste was cut shortAdd the missing end tag, or paste the whole document
Extra content follows the end of the root elementA second root element, or text after the rootWrap everything in one parent element
The entity &name; is not definedAn HTML entity such as &nbsp;, or a bare &Use &#160; or write &amp;
An attribute value must be in quotesid=7 instead of id="7"Add the quotes
The attribute name is given twice on the same tagA duplicated attributeDelete one of them
The prefix is used but never declaredA namespace prefix with no xmlns:prefixAdd the declaration on the tag or a parent
The <?xml ...?> declaration is only allowed at the very startA blank line, space or comment before itRemove whatever comes before it
A comment cannot contain two hyphens in a row (--)A -- inside <!-- ... -->Reword the comment
This CDATA section is never closedA missing ]]>Add it

Characters that XML forbids, such as stray control characters, are reported too, and so are start tags that are never finished and comments that are never closed.

Validate XML against an XSD schema

A well-formed document can still be wrong for its purpose: a text value where a number belongs, a required element missing, an element in the wrong place. A schema describes what is allowed, and the validator can check against it.

  1. Press the gear button, Advanced options.
  2. Paste your schema into XSD schema (optional). Leave it empty to check well-formedness only.
  3. Paste the XML into the XML box and press Validate.

If the XML does not match, the result is titled Does not match the schema: N errors and lists up to 100 of them. Each one gives the XPath of the element, such as /note/n[1], or /note/@id for an attribute, then a plain sentence and the line. The sentences cover:

When the problem is in the schema rather than in your XML, it gets its own box, The XSD schema is not well-formed XML or The XSD schema cannot be used, and the XML is not checked against it. A schema that imports or includes another file cannot be used, because nothing is fetched. Put all the definitions into one XSD. The validator supports XSD 1.0.

Format and pretty-print XML

When the document is valid, a Formatted XML section appears with a Copy button above the result. Choose the width in Indentation under Advanced options: 2 spaces, 4 spaces or Tab. The result updates as soon as you change it.

Formatting follows xmllint --format, so it is predictable:

Very long output is shown cut off, with a note saying how many lines are shown. Copy always gives the whole document.

Large XML files

The check runs in a background Web Worker. Very large documents are slow mostly because the browser has to draw that much text in the box: in testing, a 50 MB document with more than 600,000 lines took about 30 seconds from paste to result, and a 20 MB one about 11 seconds. The limit is 120 million characters. Over the limit, you are asked to paste a smaller piece.

What this validator does not check

There is no DTD validation, and external entities and files are not loaded, because nothing is fetched. Only XSD 1.0 is supported. A declared encoding such as ISO-8859-1 or UTF-16 is ignored, because pasted text is already Unicode. Documents that define entities which expand into far too much text are refused, and so are tags nested more than 2048 levels deep.

More tools for structured data

Working with JSON instead? Tidy it with the JSON Formatter or check it against a schema with the JSON Schema Validator. For source code in other languages there is the Code Formatter, and the Any to CSV tool turns Excel and JSON into CSV.


Frequently asked questions

How do I check if XML is well formed?

Paste the XML into the XML box and press Validate. A green Valid XML box means every tag is closed and nested correctly and the document has one root element. A red Not well-formed XML box gives the first error in plain words, with the line and column.

What is well-formed XML?

XML that follows the syntax rules: one root element, every start tag closed with a matching end tag in the right order, attribute values in quotes, no repeated attribute on a tag, and special characters such as & written as &amp;. A parser refuses a document that breaks any of these.

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

Well-formed means the syntax is correct. Valid, in the strict sense, also means the document follows a schema (an XSD or a DTD) that says which elements and values are allowed. Here, Valid XML means well-formed when the XSD box is empty, and well-formed and matching the schema when you paste an XSD. DTD validation is not supported.

What does "opening and ending tag mismatch" mean in XML?

A closing tag does not match the tag that is open at that point, so a closing tag is missing or misspelled, or two tags overlap. This validator says it like this: The closing tag </a> does not match the open tag <b> from line 1. Fix the first error it names and check again, because later errors are usually side effects of it.

Why does XML say "extra content at the end of the document"?

Something follows the end of the root element, most often a second root element, for example two records pasted one after the other. An XML document has exactly one root element. Wrap the records in a single parent element, or paste one record at a time.

Why does XML say the entity nbsp is not defined?

&nbsp; is an HTML entity. XML itself predefines only &lt;, &gt;, &amp;, &quot; and &apos;. Use the character reference &#160; for a non-breaking space, type the character itself, or declare the entity in a DTD. A bare & that does not start an entity must be written as &amp;.

What does "XML declaration allowed only at the start of the document" mean?

The <?xml version="1.0"?> line must be the very first thing in the document. A blank line, a space or a comment before it triggers this error. Delete everything above the declaration, or remove the declaration if you do not need it.

How do I validate XML against an XSD online?

Press Advanced options, paste the schema into XSD schema (optional), paste your XML into the XML box and press Validate. If the document does not match, the result lists each problem with the XPath of the element, a plain sentence and the line. The schema has to be a single XSD 1.0 document.

Can I validate a large XML file online?

Yes, up to 120 million characters. The check runs in a background worker, but a very large paste is slow because the browser has to draw all that text in the box: in testing, a 50 MB document with more than 600,000 lines took about 30 seconds from paste to result, and a 20 MB one about 11 seconds. You paste the text into the XML box, as there is no file picker.

Is my XML uploaded when I validate it?

No. The XML is parsed in your browser by libxml2 compiled to WebAssembly, and nothing is uploaded or saved. That makes it suitable for private feeds and configuration files, and nothing is fetched for a schema either.

Why can't I use my XSD that imports another file?

An xs:import or xs:include points to another file, and the validator fetches nothing from the network or from your disk. Put all the definitions into one schema document and paste that. The box The XSD schema cannot be used names the file the schema refers to.

Why did formatting remove the space between my tags?

Formatting follows xmllint --format. Whitespace-only text between tags is dropped and the indentation is applied again, so in mixed content such as <p><b>a</b> <i>b</i></p> the space between the two tags can be lost. Text inside an element is kept as written. If that space matters, keep your original and use the result only to read the structure.


Recommended

Helps keep the tools free. ✨

Images are for illustration only. As an Amazon Associate I earn from qualifying purchases.