XSD Validator
Paste an XML document and its XSD schema to check that the XML follows the schema: element order and counts, required attributes, data types, enumerations, patterns, lengths and ranges. Each error shows the line in your XML and what the schema expected.
Last updated:
Validation runs in your browser with a built-in XML Schema 1.0 engine. Nothing is uploaded. Tip: Ctrl + Enter validates.
How to use the XSD Validator
- Paste the XML into the left editor, or open or drop a file. A sample purchase order with errors loads first.
- Paste the XSD into the right editor. If it uses xs:include or xs:import, add those files with + Imported .xsd.
- Read the result. Green means the XML conforms to the schema; otherwise each error explains what was wrong and what was expected.
- Click an error to jump to its line. Lines with errors are highlighted red in the line numbers.
- Fix and re-check. Validation reruns as you type, or press Validate XML (Ctrl + Enter).
How XSD validation works
A validator walks the XML tree from the root down. The root must match a global element declaration. Each element's type then decides what it may contain:
- Simple types (like
xs:dateor a restrictedxs:string) allow text only. The text is normalised for whitespace and checked against the type and its facets. - Complex types allow attributes and, depending on the content model, child elements in a
sequence(fixed order),choice(one of) orall(any order, each at most once), repeated asminOccurs/maxOccursallow. - Identity constraints (
xs:unique,xs:key,xs:keyref) are checked last, across the elements they select.
Common XSD validation errors and fixes
| Error | Usual cause | Fix |
|---|---|---|
| No matching global element declaration | Root name or namespace differs from the schema | Add the schema's targetNamespace as xmlns in the XML |
| Element is not expected here | Wrong order in a sequence, a missing element before it, or too many repeats | Follow the order shown under Expected |
| Element is incomplete | A required child (minOccurs ≥ 1) is missing at the end | Add the listed element |
| Attribute is not allowed | Typo, wrong case, or an attribute the type does not declare | Names are case-sensitive; check the spelling |
| Value is not one of the allowed values | Value outside an xs:enumeration | Use one of the listed values exactly |
| Value does not match the pattern | xs:pattern regex fails; patterns match the whole value | Check the format, e.g. ORD-\d{5} needs exactly five digits |
| Not a valid date | xs:date needs YYYY-MM-DD, and the day must exist | Write 2026-03-14, not 14/03/2026 |
| Has 3 decimal places | fractionDigits or totalDigits exceeded | Round the number |
Tips
- elementFormDefault matters. With
elementFormDefault="qualified", child elements must be in the target namespace too, which a defaultxmlns="…"on the root takes care of. - xsi:schemaLocation is only a hint. Validators, including this one, use the schema you supply rather than downloading the location from the XML.
- No schema yet? Draft one from a sample document with the XML to XSD Generator, and check plain syntax with the XML Validator.
Frequently asked questions
What is the difference between well-formed and valid XML?
Well-formed XML follows the basic syntax rules: one root element, properly nested and closed tags and quoted attributes. Valid XML is well-formed and also follows a schema, which defines which elements and attributes may appear, in what order, how often and with which data types. This tool checks both: syntax first, then the XSD rules.
How do I validate XML against an XSD?
Paste the XML on the left and the schema on the right. The root element of the XML must match a global xs:element declared in the schema, including its namespace. Every child element, attribute and text value is then checked against the declared types, and each violation is listed with its line number.
Why do I get 'No matching global element declaration'?
The root element name or namespace does not match a top-level xs:element in the schema. If the schema has a targetNamespace, the XML must declare the same namespace, for example xmlns="urn:example:orders". Local elements declared inside a type cannot be used as the root.
What does 'Element is not expected here' mean?
The element is not allowed at that point of the content model: it may be in the wrong order inside an xs:sequence, appear more often than maxOccurs allows, or not be declared at all. The message lists the elements the schema expected at that position, which usually points straight to the fix, such as a missing required element before it.
Does it support xs:include and xs:import?
Yes, but the browser cannot fetch files from your disk or network automatically. Add the referenced schema files with + Imported .xsd. Until they are added, the tool warns you and skips the types and elements that come from the missing files.
Which XSD version is supported?
XML Schema 1.0, which is what most real-world schemas use. XSD 1.1 features such as xs:assert, xs:alternative and xs:override are not evaluated; when a schema uses them, a warning is shown instead. Regular expression patterns are translated to JavaScript, so a few rare XSD regex features such as Unicode block names are approximated.
Is my XML uploaded anywhere?
No. Both files are parsed by your browser's XML parser and validated by JavaScript on this page, so private data and internal schemas never leave your computer.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.