Validating XML against an XSD schema
XSD validation checks that an XML document follows the rules in an XML Schema: which elements may appear and in what order, which attributes are required, and what type each value must have (an integer, a date, one of a fixed list). A document can be perfectly well-formed and still fail, which is exactly what this catches before a partner's system rejects your file.
The schema language is defined by the W3C in XML Schema Part 1: Structures and Part 2: Datatypes. This tool validates against version 1.0 of those rules.
This one runs on our server
Most tools on this site work inside your browser. This one doesn't, because browsers have no built-in XSD validator. When you click Validate, both boxes are posted to our server, where PHP loads the XML into a DOMDocument and calls schemaValidateSource, which uses the libxml2 library. The server never loads anything your input points to: external entities and DTDs are not fetched, and neither are schema files named by xs:import or xs:include. The result goes straight back to the page and the tool doesn't store your input. Even so, treat it as sending the data to a third party and leave out anything confidential.
Worked example
The schema below describes an order with a required id, a customer name, a positive quantity and an optional ship date:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="customer" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="shipDate" type="xs:date" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Here's what the validator returned for different versions of the document:
| What's wrong with the order | Message |
|---|---|
| Nothing | The XML document is valid against the given XSD schema. |
| Quantity is 0 | Element 'quantity': '0' is not a valid value of the atomic type 'xs:positiveInteger'. |
No id attribute |
Element 'order': The attribute 'id' is required but missing. |
quantity before customer |
Element 'quantity': This element is not expected. Expected is ( customer ). |
| Ship date written 02/11/2026 | Element 'shipDate': '02/11/2026' is not a valid value of the atomic type 'xs:date'. |
Extra note element at the end |
Element 'note': This element is not expected. Expected is ( shipDate ). |
Root element is invoice |
Element 'invoice': No matching global declaration available for the validation root. |
| A closing tag doesn't match | Invalid XML: Opening and ending tag mismatch: customer line 1 and order |
Schema messages are prefixed "XML does not validate against the schema:". Note the date row: xs:date only accepts the ISO 8601 form 2026-11-02.
One more message you might meet: if your document uses entities defined in its own DOCTYPE (&company; and the like), validation stops with an "Internal error" saying entity references aren't supported. Replace them with their text before validating.
Steps
- Paste the XML document into the first box.
- Paste the complete schema into the second box. Both are required.
- Click Validate and read the first error.
- Fix it and validate again until the document passes.
If the message starts with "The XSD schema is invalid", the problem is in the schema itself (for example a misspelled built-in type such as xs:strng, or an XSD 1.1 construct), not in your document. Check the schema's syntax with the XML validator and compare type names against the specification.
Namespaces and the root element
The most common "No matching global declaration" failure is a namespace mismatch. If the schema declares targetNamespace="urn:shop", the document's root has to be in that namespace too. With such a schema, a plain root order element fails, while the same element with xmlns="urn:shop" passes. Also remember that only globally declared elements (direct children of xs:schema) can be the root.
Keep the schema self-contained
Real-world schemas are often split across files with xs:include and xs:import. Those references are never followed here, and the tool tells you the schema refers to an external file rather than guessing. Paste a single schema with all the definitions it uses written inline. If a standard schema is too large to merge by hand, validate it locally with xmllint --schema schema.xsd file.xml, which uses the same libxml2 engine.
Related tools
Once the document validates, the XPath evaluator is useful for checking specific values, and the XML formatter makes long documents readable. For writing or editing schemas with syntax highlighting, use the online XML editor.
Last updated