How to Validate XML Against an XSD Schema (and Fix the Errors)
XML can be well-formed, with every tag closed and every character escaped, and still be wrong for the system that receives it: a missing ID, a price written as text, elements in the wrong order. That’s what an XSD schema catches. E-invoices, bank files, product feeds and most data exchanges between companies come with one, and files that don’t match it are rejected.
This guide shows how to check a file with the free XML Validator and explains the error messages one by one. For the basics of well-formed XML, see how to format and validate XML.
What an XSD schema says
A schema is itself an XML file. This one describes a catalog of books:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="catalog">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>xs:elementdeclares an element; the outermost one (catalog) is the root.xs:sequencelists child elements in order:titlemust come beforeprice.maxOccurs="unbounded"allows any number of books; by default an element must appear exactly once.typesets what a value may be:xs:stringis any text,xs:decimala number such as 29.95.use="required"makes theidattribute compulsory.
How to validate XML against a schema
- Open the XML Validator and add your XML on the left: paste it, click Open file or drop the file.
- Add the schema on the right, in XSD schema (optional). The Sample buttons load the example on this page.
- Click Validate XML. A green ✓ Valid means the file matches. Otherwise you get, for example, ✗ 2 problems found against the schema, with each problem’s line and a Go to line button.
Here is the sample XML. It looks fine, but it breaks the schema twice:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101">
<title>XML & JSON for Everyone</title>
<price>29.95</price>
</book>
<book>
<title>Daten für alle</title>
<price>free</price>
</book>
</catalog>The validator reports line 7 (the second book has no id) and line 9 (the price is “free”, which isn’t a number).
The error messages, explained
The schema check uses libxml2, the standard XML library behind many programs, so its messages are in English. These are the ones you’ll see most:
Element 'book': The attribute 'id' is required but missing.
A required attribute is missing. Add it:<book id="bk102">.Element 'price': 'free' is not a valid value of the atomic type 'xs:decimal'.
The value doesn’t fit the type. Decimal numbers use a dot (29.95, not29,95), with no currency symbol, spaces or words. Other types work the same way:xs:datewants2026-10-30,xs:booleanwantstrueorfalse.Element 'price': This element is not expected. Expected is ( title ).
The element is in the wrong place: the schema’s sequence saystitlecomes first. Put the elements in the order the schema lists them.Element 'isbn': This element is not expected.
The schema doesn’t allow this element here at all. Check its spelling and upper/lower case, or remove it.Element 'order', attribute 'status': [facet 'enumeration'] The value 'sent' is not an element of the set {'open', 'paid', 'shipped'}.
Only the listed values are allowed. Use one of them, spelled exactly the same.Element 'order': No matching global declaration available for the validation root.
The schema has nothing for the root element. Usually the namespace is wrong or missing: if the schema has atargetNamespace, the XML needs the samexmlns="…"on its root element.
Fix problems from the top. One mistake can cause more messages further down, so re-validate after each fix; the list often gets shorter than expected.
Good to know
- One schema file. Schemas that pull in other files with
xs:includeorxs:importcan’t load them here; the report says which file was missing. Copy those definitions into one schema first. - XSD 1.0. Features only in XSD 1.1, such as assertions, aren’t supported. Most schemas in use are XSD 1.0.
- First run. The checking engine (about 1 MB) downloads the first time you validate against a schema; after that it’s instant.
- No schema? Leave the box empty to check only that the XML is well-formed.
More XML tools
- XML Formatter: make the file readable first, or explore it in the Tree view.
- XPath Tester: find the elements a message points to. See how to use XPath.
- CSV to XML: build the XML from a spreadsheet, then validate it here.
Is my XML uploaded?
No. The check, including the schema validation, runs in your browser, so your XML and your schema never leave your device.
Frequently asked questions
Where do I get the XSD?
From whoever receives the file: the system’s documentation, the standard you have to follow (e-invoicing and banking standards publish their schemas), or your partner’s developers.
Are DTDs supported?
No, the validator checks against XSD schemas only.
Does validating change my XML?
No. It only reads the file and reports problems. Fix them in your editor or in the box, then validate again.