/xXSDHub
PRACTICAL XML NOTES

Fix “This element is not expected” in XSD validation

Published by XSDHub · How our guides and examples are made

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.

TRY THE FIX

A broken example and a working correction

These examples were checked on 26 October 2026 using XSDHub’s libxml2-based engine. Other validators may phrase the same problem differently.

What XSDHub reports

Element 'price': This element is not expected. Expected is ( quantity ).

Before: fails XSD validation

<order>
  <price>12.50</price>
  <quantity>3</quantity>
</order>
Try the broken example →

After: passes this check

<order>
  <quantity>3</quantity>
  <price>12.50</price>
</order>
Try the corrected example →
Complete XSD used for both examples
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="order"><xs:complexType><xs:sequence><xs:element name="quantity" type="xs:positiveInteger"/><xs:element name="price" type="xs:decimal"/></xs:sequence></xs:complexType></xs:element></xs:schema>

The buttons open a new workbench page with the example loaded. Choose Validate XML to run the check. Your own files are not uploaded.

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.

Checking the same rule across many files?

Start with the free single-document check. Pro adds batches of up to 25 XML files and 10 saved schemas; Team adds larger batches and a shared library. Both use the same validation engine.

Compare batch-validation plans →

Primary references