This XML validator checks whether a document is well-formed, which is the first thing any XML parser demands. Paste your XML, press Validate XML, and you'll either see a confirmation with a short summary of the document, or the first problem with the line and column where it was found. The check runs in your browser, so configuration files, feeds and data exports never leave your computer. It's a quick way to find the unclosed tag or stray character that is stopping a file from loading.
What does well-formed mean?
A well-formed document in XML is one that follows the syntax rules of the XML 1.0 specification. At its base level, content must be delimited with a beginning and an end tag, and it must be properly nested, with children inside parents and parents inside the root. Other key rules are that tags are case sensitive, that attribute values are delimited with quotation marks, and that there is a single root element that contains all the other elements. The special characters < and & can't appear in text except when they are doing their markup jobs.
How to use the XML validator
- Paste your XML into the box. You can paste a whole file.
- Press Validate XML.
- Read the result. Well-formed XML shows the root element, the number of elements and attributes, and the deepest nesting level.
- Fix the first problem if there is one, using the line and column shown, then validate again.
Worked example
Paste this short document:
<note>
<to>Ann</from>
</note>
The validator reports that it's not well-formed. The problem is that the closing tag </from> doesn't match the open tag <to>, and the place is line 2, column 10. Change </from> to </to> and validate again. This time the result is well-formed XML, with note as the root element, 2 elements, 0 attributes and a deepest nesting level of 2.
Errors the validator finds
| Problem | Example | Fix |
|---|---|---|
| Tag never closed | <a><b> | Add the missing closing tags |
| Tags closed in the wrong order | <a><b></a></b> | Close the inner tag first |
| Different capital letters | <Item></item> | Make both names identical |
| More than one root | <a/><b/> | Wrap everything in one element |
| Unquoted attribute | <a id=1/> | Write id="1" |
| Repeated attribute | <a id="1" id="2"/> | Keep one of them |
| Plain ampersand | Tom & Jerry | Write & |
| Plain less-than sign | 1 < 2 | Write < |
Well-formed and valid aren't the same
The two words are often mixed up. A valid XML document is defined in the XML specification as a well-formed document that also conforms to the rules of a Document Type Definition, or DTD. So every valid document is well-formed, but a well-formed document doesn't need a DTD at all. This tool checks the first level. It doesn't read a DTD or an XSD schema, so it can't tell you whether an element is allowed in a particular place or whether a required field is missing. If your file must match a schema, check well-formedness here first, then run it through the software that owns the schema.
Why XML is so strict
An XML processor that meets a violation of the well-formedness rules is required to report the error and to stop normal processing. This policy is sometimes called draconian, and it's a notable contrast with programs that process HTML, which are designed to produce a reasonable result even when the markup has severe errors. The benefit is that every program reads the same XML in the same way. The cost is that a single missing character can stop a whole file from loading, and that's why a validator is so useful.
Why only the first problem is shown
Once a parser hits an error in XML, everything after it is uncertain. One unclosed tag near the top can make every later closing tag look wrong. For that reason the validator stops at the first problem, as a real XML parser does. Fix it, press Validate XML again, and repeat until the document passes. In a long file, the place reported is where the parser noticed the fault, so the true cause is sometimes a little earlier, such as an opening tag a few lines above.
Names, comments and special sections
Tag names can't contain spaces, and they can't start with a hyphen, a full stop or a digit. Comments start with <!-- and end with -->, and they can't contain two hyphens in a row. A CDATA section lets you include text with < and & characters without escaping them, which is handy for code samples. The XML declaration is optional, but if you include it, it must be the very first thing in the file, with no blank line or space before it.
Where it helps
- Sitemaps and RSS feeds that a search engine or reader has rejected.
- Configuration files for apps, build tools and servers.
- SVG images edited by hand.
- Data exports from spreadsheets, accounting or shop software.
Common mistakes
- Forgetting to escape an ampersand in a company name or a web address.
- Leaving a space or blank line before the XML declaration.
- Treating XML like HTML. Tags such as <br> must be closed, as <br/>.
- Expecting a schema check. This tool checks syntax only.
Related tools
Turn data from one format into the other with the JSON to XML converter, check JSON with the JSON formatter and validator, and tidy markup with the HTML formatter.
What next
Use this often? Add XML Validato to your Home screen.
Frequently asked questions
What does the XML validator check?
It checks that the XML is well-formed: one root element, every tag closed and nested in order, quoted attributes with no repeats, and no stray less-than signs or ampersands.
Does it validate against a DTD or XSD schema?
No. It checks syntax only. Use the software that owns the schema for that step.
Why does it show only one error?
After the first error, the rest of the document can't be read reliably, so it stops there, as an XML parser does. Fix it and validate again.
Is my XML uploaded?
No. The check runs in your browser, and nothing is sent to a server.
Are XML tags case sensitive?
Yes. An opening tag named Item and a closing tag named item don't match, so the document isn't well-formed.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.