XML Validator Guide: How To Check and Fix XML Errors
An XML validator checks whether your XML is correctly written. It helps find missing tags, broken nesting, invalid characters and schema errors before your XML causes problems in an app, feed or integration.
- XML validation checks whether XML is correctly structured.
- Well-formed XML follows the basic XML syntax rules.
- Schema validation checks XML against rules such as XSD.
- Most XML errors come from missing tags, bad nesting or case mismatches.
What is XML validation?
XML validation is the process of checking whether an XML document follows the correct rules.
There are two common levels of checking:
| Type | What it checks |
|---|---|
| Well-formed XML | Checks basic syntax, such as tags, nesting and one root element. |
| Schema-valid XML | Checks whether the XML follows extra rules defined by a schema such as XSD. |
Valid XML example
This XML is valid because the tags match, the structure is nested correctly and there is one root element.
<cleaningTeam>
<employee>
<name>Jane Smith</name>
<role>Senior Floor Cleaner</role>
</employee>
</cleaningTeam>
Invalid XML example
This XML is invalid because the opening and closing tags do not match.
<name>Jane Smith</Name>
XML is case-sensitive. <name> and </Name> are not the same tag.
Fixed XML example
The fixed version uses matching lowercase tags.
<name>Jane Smith</name>
Common XML validation errors
| Error | Example problem | How to fix it |
|---|---|---|
| Missing closing tag | <title>How to Clean Floors |
Add the closing tag: </title> |
| Case mismatch | <name>Jane</Name> |
Use exactly matching tag names. |
| Wrong nesting | <b><i>text</b></i> |
Close the inner element before the outer element. |
| Multiple root elements | Two top-level elements in one document | Wrap everything inside one root element. |
| Invalid characters | Using raw & inside text |
Escape it as &. |
Missing closing tag example
A missing closing tag is one of the easiest XML errors to make.
<book>
<title>How to Clean Floors
</book>
The <title> tag needs a matching </title> closing tag.
Wrong nesting example
XML elements must be closed in the correct order.
<employee>
<name>Jane Smith
</employee>
</name>
The most recently opened tag should be closed first. Think of XML tags like stacking plates: last on, first off.
What is XML schema validation?
XML schema validation checks your XML against a defined set of rules. A schema can specify which elements are allowed, which fields are required and what type of data each field should contain.
For example, a schema might require an employee record to contain a name, a role and an employeeId.
How to validate XML
- Paste your XML into an XML validator or formatter.
- Check for syntax errors first.
- Fix missing or mismatched tags.
- Check nesting and root element structure.
- If using a schema, validate against the XSD or schema rules.
Validate or format XML online
Use CheeseBridge XML tools to inspect, format and clean up your XML in the browser.
Open XML Formatter Open XML ViewerTrusted XML references
For official and technical references, see:
Frequently asked questions
What does an XML validator do?
An XML validator checks whether XML is correctly written. It can detect problems such as missing tags, broken nesting, invalid characters and schema rule violations.
Is valid XML the same as well-formed XML?
Not always. Well-formed XML follows basic XML syntax rules. Valid XML can also mean the document follows a schema such as XSD.
Why does XML fail validation?
XML usually fails validation because of missing closing tags, mismatched case, incorrect nesting, invalid characters or schema rule errors.