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 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.

Order-sensitive schema
<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>
Valid declared order
<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.

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.