Resell services with the EthicalSMM API

XML Validator

Check that XML is well-formed and see the line and column of the first error, or a summary of elements, attributes and nesting.

Was this tool helpful?

Thanks for the feedback!

This XML validator checks whether a piece of XML is well-formed: every tag closed and correctly nested, every attribute quoted, and a single root element around everything. If something is wrong it points to the line and column of the first problem, and if the XML is fine it gives a short summary of the document. It is useful for developers, anyone checking a sitemap or RSS feed by hand, and people importing XML into accounting or ERP software.

How to use it

Paste your XML into the box and press Validate XML. Spaces and blank lines at the very start and end are trimmed first, so an empty line above <?xml version="1.0"?> will not cause a false error. An empty box gives the message "Paste the XML you want to check."

The check is done by your browser's own XML parser (the DOMParser built into Chrome, Edge, Firefox and Safari). Nothing is uploaded, which matters when the file holds customer names or prices. It also means the exact wording of an error comes from the browser, so Chrome and Firefox describe the same mistake a little differently.

Reading the result

When the XML parses cleanly, the result starts with "✓ Well-formed XML." and then lists:

  • the root element, which is the outermost tag;
  • the namespace, shown only when the root element has one, for example from a default xmlns="…";
  • the number of elements, counting the root;
  • the number of attributes across all elements, where namespace declarations such as xmlns count too, because the browser treats them as attributes;
  • the deepest nesting, in levels. A root element with no children is 1 level.

When it fails, the result starts with "✗ Not well-formed." If the browser reported a position you then see "Problem near line X, column Y.", followed by the browser's own description. A parser stops at the first fatal error, so fix that one and validate again. There may be more further down.

Worked example

Here is a small invoice file:

<?xml version="1.0" encoding="UTF-8"?>
<invoice xmlns="urn:example:invoice" number="INV-0425" currency="INR">
  <buyer state="MH">
    <name>Sharma Traders</name>
  </buyer>
  <items>
    <item qty="2" rate="1250"><name>Steel bottle</name></item>
    <item qty="1" rate="899"><name>Lunch box</name></item>
  </items>
</invoice>

The tool reports root element <invoice>, namespace urn:example:invoice, 8 elements, 8 attributes and a deepest nesting of 4 levels. The elements are invoice, buyer, items, two item tags and three name tags. The attributes are xmlns, number and currency on the root, state on buyer, and qty and rate on each item. The deepest path is invoice, then items, then item, then name.

The placeholder example, <note><to>Asha</to><from>Ravi</from></note>, gives 3 elements, 0 attributes and 2 levels. Delete </from> and it becomes "✗ Not well-formed.", with the position pointing at the closing </note>, because that is where the parser notices the from tag was never closed.

Common reasons XML is not well-formed

  • A bare ampersand, as in Shah & Sons. Write it as &amp;.
  • HTML entities such as &nbsp; or &rsquo;. XML only predefines five: &lt;, &gt;, &amp;, &quot; and &apos;. Use a numeric reference like &#160; or the character itself.
  • Different case in the start and end tag. <Item>…</item> is a mismatch, because XML names are case-sensitive.
  • Attribute values without quotes, such as qty=2.
  • Two root elements, for example two <url> blocks in a sitemap with no <urlset> around them.
  • Text or a comment before the <?xml …?> declaration. Only whitespace may come before it, and the tool trims that for you.

Well-formed is not the same as valid

This tool checks syntax only. It does not test the file against a DTD or an XML Schema (XSD), so it cannot tell you that a required element is missing or that a date is in the wrong format. A file can be perfectly well-formed and still be rejected by the system it is meant for. Once the syntax passes, use the XML Formatter to indent the file so it is easier to read, or the XML to JSON converter if the data needs to go into a JSON API.

Frequently asked questions

What is the difference between well-formed and valid XML?
Well-formed XML follows the basic syntax rules: closed and properly nested tags, quoted attributes and one root element. Valid XML is well-formed and also matches a DTD or XML Schema; this tool checks only the first.
Why does &nbsp; make my XML invalid?
XML defines only five named entities: &lt;, &gt;, &amp;, &quot; and &apos;. Replace &nbsp; with the numeric reference &#160; or with an actual non-breaking space character.
How do I find which line has the XML error?
Paste the XML and press Validate XML. When the browser reports a position, the result says "Problem near line X, column Y", which is where the parser first gave up.
Can I check a sitemap.xml with this tool?
Yes, paste the sitemap content to confirm it is well-formed. It does not check sitemap rules such as URL limits or date formats, only the XML syntax.
Is my XML uploaded anywhere?
No. The browser's built-in parser does the check on your device, so the XML never leaves your computer.
Why does the tool only show one error?
The XML specification says a parser must stop normal processing at the first fatal error, and browsers report only that one. Fix it and validate again to find the next one, if any.

Related guides

Related tools

People also used

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.