Codepackr / xml / XSD & XML Schema Validator

XSD & XML Schema Validator

Validate XML structures against W3C XSD schema definitions, element constraints, and data types locally in your browser.

Client-Side Execution & Privacy Guarantee

This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.

Schema validation checks that an XML instance conforms to the structure, data types, and constraints declared in an XSD. Unlike well-formedness checking, it verifies element order, occurrence limits, attribute presence, and the lexical form of simple types.

The validator runs locally, so schemas and instances never leave the browser. It reports the first error or a list of errors with line and column information, making it practical for iterative development and for confirming that generated samples still match an evolving schema.

What validation checks

The process first confirms that the document is well-formed, then matches each element and attribute against the declarations in the schema. Complex types enforce sequence, choice, or all content models and the minOccurs/maxOccurs constraints. Simple types enforce the lexical space of the built-in or derived type, including length, pattern, enumeration, and numeric range facets.

Namespace correctness is required: an element in the wrong namespace is reported as undeclared even if its local name matches. xsi:type, xsi:nil, and schemaLocation attributes are honored when present.

Common error categories

cvc-complex-type errors indicate missing required children, unexpected elements, or violations of order. cvc-type and cvc-datatype-valid errors signal that a value does not match the declared simple type or one of its facets. cvc-identity-constraint errors arise when key, keyref, or unique constraints fail.

Schema-resolution failures occur when an xs:import or xs:include cannot be satisfied from the supplied schema text. Because the validator does not fetch remote resources, all required schema documents must be pasted or concatenated beforehand.

Practical workflow

Paste the XSD first, then the XML instance. The tool compiles the schema and validates the instance in one step. Error messages include the element path and the constraint that was violated so you can locate the problem quickly.

After correcting the instance or the schema, re-validate. The same pair of documents can be used with the sample generator and the inference tool to keep the contract and the examples aligned.

When to use this tool

  • You need to confirm that an XML message satisfies a partner’s published schema before sending it.
  • You are developing an XSD and want immediate feedback on whether sample documents still validate.
  • You received a validation failure from a remote service and want to reproduce it locally.
  • You generated a sample with the XSD-to-XML tool and need to verify it against the original schema.
  • You are teaching or learning the difference between well-formedness and validity.

How to use the XSD & XML Schema Validator

  1. Paste the complete XSD schema into the schema pane. Include any imported schemas by concatenation if necessary.
  2. Paste the XML instance into the document pane.
  3. Click Validate. The tool reports success or lists each violation with location information.
  4. Examine the first error; correct the instance or the schema and re-validate.
  5. Use the element path in the message to navigate directly to the offending node.
  6. When the document validates, copy it for use in tests or documentation.
  7. If schema resolution fails, verify that every targetNamespace and import is present in the pasted text.

Worked examples

Valid simple document

Input
Schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="note" type="xs:string"/>
</xs:schema>

Instance:
<note>Hello</note>
Output
Valid

The instance matches the declared element and type.

Missing required element

Input
Schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="person">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:string"/>
        <xs:element name="age" type="xs:integer"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Instance:
<person><name>Ada</name></person>
Output
Error: cvc-complex-type.2.4.b: The content of element 'person' is not complete. One of '{age}' is expected.

The required age child is absent.

Common mistakes and tips

  • A document can be well-formed yet invalid; always run schema validation when a contract exists.
  • Namespace mismatches are the most frequent source of “element not declared” errors. Compare the xmlns of the instance with the targetNamespace of the schema.
  • Facet violations (maxLength, pattern, enumeration) produce cvc-type or cvc-enumeration-valid messages; the value itself is usually shown in the message.
  • Large schemas with many imports are easiest to validate when concatenated into a single self-contained document.
  • After inference or sample generation, immediately validate the pair to catch cardinality or type mismatches introduced by the other tools.

Frequently asked questions

Why does validation say an element is not declared when the name looks correct?

The element is probably in a different namespace from the one expected by the schema. Check both the instance xmlns and the schema targetNamespace.

Can the validator fetch schemas from schemaLocation URLs?

No. All schema documents must be supplied in the schema pane; remote resolution is disabled for privacy and reliability.

Does it support XSD 1.1 assertions?

No. Only XSD 1.0 constructs are validated.

What is the difference between a fatal error and a validity error?

A fatal error means the XML is not well-formed (unclosed tags, illegal characters). A validity error means the document is well-formed but violates the schema.

Are identity constraints checked?

Yes. key, keyref, and unique constraints are enforced when they appear in the schema.