PARSER ERROR CODES

cvc-complex-type.2.4.a: invalid child element

XSDHub · Tested 5 November 2026 · How we test guides

Xerces has reached a child whose expanded name cannot occupy the current position in its parent. The document may be perfectly well-formed XML. Validation fails because the parent’s content model expects something else at this point.

What the message literally means

The phrase “starting with element” identifies the first child that cannot be consumed. The expected set describes the next legal transition, rather than every element that appears anywhere in the schema. In this order, quantity must precede price; moving price after quantity repairs the sequence without changing either value.

Three common causes to check first

  1. Children appear in a different order from xs:sequence. A serializer that sorts properties alphabetically can produce valid tags in an invalid sequence.
  2. A required predecessor is missing. Adding the child named in the message at the end may still fail, because it belongs before the reported element.
  3. The child has the wrong namespace, spelling or parent. A declaration elsewhere in the XSD does not make that element legal in every container.

Repair and retest

Locate the declaration of the reported parent, then walk its sequence or choice from the first child. Stop at the earliest mismatch and compare that child with the expected set. Fix the ordering in the producer rather than repeatedly moving whichever element the latest message names. Retest the full document because an early mismatch can hide later failures.

When this is a namespace problem

Suspect namespaces when the expected local name already matches the visible tag. Compare the namespace URI and local name together, including inherited xmlns declarations. A prefix change alone does not change identity when it remains bound to the same URI; removing a prefix can change identity when no matching default namespace exists.

Reading equivalent reports

In System.Xml.Schema this example says “has invalid child element”; libxml2 says “This element is not expected”. These phrases describe the same tested sequence failure. Do not replace xs:sequence with xs:any merely to silence it: the receiving application may still require the original field order.

Complete tested XML and XSD pairs

Open either variant in the workbench, then choose Validate XML. Loading an example does not run validation or send documents; server checks require the existing permission checkbox.

These transcripts were captured on 5 November 2026 from the exact files shown below. Download all measured results and SHA-256 hashes.

Unexpected child / cvc-complex-type.2.4.a

Broken XML

<order>
  <price>12.50</price>
  <quantity>3</quantity>
</order>
Broken complete XSD
<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>

Download XML · Download XSD

Open broken pair →

Corrected XML

<order>
  <quantity>3</quantity>
  <price>12.50</price>
</order>
Corrected complete XSD
<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>

Download XML · Download XSD

Open corrected pair →

Same specimen across engines

EngineBroken: actual reportCorrected
Apache Xerces-J 2.12.2
Validation
cvc-complex-type.2.4.a: Invalid content was found starting with element 'price'. One of '{quantity}' is expected.
PASS
.NET 8.0.33 · System.Xml.Schema
Validation
The element 'order' has invalid child element 'price'. List of possible elements expected: 'quantity'.
PASS (no warnings)
XSDHub libxml2/WASM 0.7.2
Validation
Element 'price': This element is not expected. Expected is ( quantity ).
PASS
XSDHub xmlschema 4.3.1 · XSD 1.0
Validation
Unexpected child with tag 'price' at position 1. Tag 'quantity' expected.
PASS
SaxonEE comparison: cvc-complex-type.2.4.a describes the corresponding XSD constraint. No Saxon-EE run or wording is claimed; an EE licence is unavailable in this test environment. Saxon-HE does not provide XSD validation.Not run

Saxon comparison and test scope

Saxonica documents XSD processing as an Enterprise Edition feature. The Saxon rows map the named constraint, rather than presenting an invented message. The four measured rows are Xerces, .NET, the shipped workbench engine and XSDHub’s second engine.

The corrected results apply to these self-contained XSD 1.0 specimens. They do not establish business-rule acceptance for a different document or schema version.

Continue the diagnosis

All parser error codes · XML and XSD validator

Primary references