Skip to main content

Search 400 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XSD guide

How to validate XML against an XSD

Separate parsing from schema validation, load the complete schema set, and reduce validation errors to the smallest failing instance.

8 min read · Updated 2026-08-21

The short answer

First confirm that both the XML instance and schema documents are well-formed. Then validate the instance with the intended schema set, including every import and include, and fix the first structural error before interpreting the messages that follow it.

Pass the parsing gate first

Schema validation never repairs malformed XML. A missing quote or unclosed tag prevents the validator from constructing the element tree whose names, order, values, and attributes the XSD constrains.

  • Parse the instance document.
  • Parse every XSD document in the schema set.
  • Resolve imports and includes through an explicit catalog or controlled base URL.
  • Only then run schema validation.

Match namespaces to declarations

The instance root's expanded name — namespace URI plus local name — selects a global declaration. A visually identical prefix is irrelevant, and xsi:schemaLocation is a hint rather than proof that the intended schema was loaded.

Namespaced instance
<product xmlns="urn:example:catalog" id="42">
  <name>Notebook</name>
</product>
Matching schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:example:catalog"
           xmlns="urn:example:catalog"
           elementFormDefault="qualified">
  <xs:element name="product">
    <xs:complexType>
      <xs:sequence><xs:element name="name" type="xs:string"/></xs:sequence>
      <xs:attribute name="id" type="xs:integer" use="required"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

Fix the earliest contract mismatch

One unexpected child can shift the validator's view of the whole remaining sequence. Reduce the instance to its root and the smallest failing branch, fix the first message, and validate again before acting on the rest.

Keep a minimal valid instance beside each schema version. It proves that the schema set resolves and gives later failures a known-good comparison point.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.