XSD guide
How to fix “Element is not expected” in XSD
Use the expected-element list to find namespace, order, or occurrence mistakes instead of deleting the child the validator names.
8 min read · Updated 2026-08-21
The short answer
The named element is valid XML but cannot occur at the validator's current position in the schema content model. Compare its expanded name, inspect the expected-element list, and check earlier siblings first: a missing or out-of-order child often makes the next correct child look unexpected.Read the current position in the content model
In an xs:sequence, the validator advances through declared particles in order. If a required child is absent, the following child is where the mismatch becomes observable, so the message may point one element after the actual omission.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person"><xs:complexType><xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
</xs:sequence></xs:complexType></xs:element>
</xs:schema><person><firstName>Ada</firstName><lastName>Lovelace</lastName></person>Compare expanded names before local names
A child with the right local name in the wrong namespace is a different declaration. Check the instance default namespace, elementFormDefault, imported schemas, and whether a prefix resolves to the URI the schema expects.
- Inspect namespace URI plus local name for the unexpected child.
- Check whether local elements are qualified or unqualified by the schema.
- Confirm the correct schema version and imported namespace set are loaded.
- Do not rename a prefix when the bound URI is the actual mismatch.
Reduce siblings until the transition is clear
Keep the root and the smallest parent that fails, then add children back in schema order. This separates a wrong child from a correct child made unexpected by an earlier cardinality or choice decision.
After the first error is fixed, validate again. Later messages are often consequences of the same lost position and should not be repaired independently.
Prove the fix
- Run the reduced instanceProve the first failing transition before restoring the full document.
- Read the schema errorCompare namespace, order, choice, and cardinality causes.
- Review sequence and choiceLocate whether the validator expected the next ordered child or another branch.
Related guides
- How to validate XML against an XSDSeparate parsing from schema validation, load the complete schema set, and reduce validation errors to the smallest failing instance.
- XSD sequence vs choiceWhen child order is fixed, when alternatives are exclusive, and how minOccurs and maxOccurs change the meaning of an XSD compositor.
- XML namespace prefix vs URIUnderstand why prefixes are replaceable aliases, why namespace URIs are compared literally, and how expanded names keep documents interoperable.
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.