# Fix “This element is not expected” in XSD validation

Source: https://xsdhub.com/learn/xsd-element-not-expected

Debug unexpected XML elements by checking sequence, namespace, spelling and occurrence rules. Try a complete failing and corrected XML/XSD pair.

## Start with the expected element

The example places price before quantity, while xs:sequence requires quantity first. Reorder the XML to follow the agreed schema. The message names price because that is where the document stops matching the content model.

## Use the complete schema below

The schema is deliberately small: an order has one positive quantity followed by one decimal price. The same principle applies to larger schemas, but use the actual schema supplied by your receiver before changing production data.

## When changing the order does not fix it

Compare namespace URI and local element name, including case. Then inspect the parent declaration: an element might be permitted elsewhere but not here. Check whether an earlier required element is missing, a choice branch has already been used, or maxOccurs has been exceeded.

## Avoid weakening the schema to hide the error

Changing xs:sequence to an unrestricted model or adding xs:any may accept documents the receiver cannot use. Fix the document or agree a schema change with the system owner. Do not delete an unexpected field without understanding its meaning.

## Retest both syntax and schema

Well-formed XML can still fail this check. Use XML + XSD mode with both inputs. This example uses a single self-contained XSD 1.0 file; XSDHub can resolve local imports and includes when the referenced files are loaded in the project loader, but does not fetch remote schema URLs.

## Primary references

- [W3C XML Schema primer: content models](https://www.w3.org/TR/xmlschema-0/)
