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
xmlnscount 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&. - HTML entities such as
or’. XML only predefines five:<,>,&,"and'. Use a numeric reference like 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?
Why does make my XML invalid?
How do I find which line has the XML error?
Can I check a sitemap.xml with this tool?
Is my XML uploaded anywhere?
Why does the tool only show one error?
Related guides
- Free Developer Tools That Replace a Dozen Browser Tabs Free developer tools grouped by job: format, convert, encode, generate and test. What each one does, which run on the server, and the limits to know f...
- How to Beautify CSS, HTML and XML (Online, VS Code, Prettier) Beautifying adds line breaks and indentation so minified CSS, HTML or XML is readable again. How the free formatters work, their limits, and VS Code a...
- How to Format JSON: Pretty-Print, Validate and Read Errors Paste JSON into a formatter to indent it and catch errors. The exact syntax rules, how to read an error position, and how to do it in VS Code, Python...