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

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.

## Literal meaning

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

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

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.

## Namespace checks

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.

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.

## Unexpected child / cvc-complex-type.2.4.a — Broken

```xml
<order>
  <price>12.50</price>
  <quantity>3</quantity>
</order>
```

```xml
<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>
```

[Open broken pair](https://xsdhub.com/?example=parser-unexpected-child&variant=bad#workbench)

## Unexpected child / cvc-complex-type.2.4.a — Corrected

```xml
<order>
  <quantity>3</quantity>
  <price>12.50</price>
</order>
```

```xml
<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>
```

[Open corrected pair](https://xsdhub.com/?example=parser-unexpected-child&variant=good#workbench)

### Apache Xerces-J 2.12.2

```text
cvc-complex-type.2.4.a: Invalid content was found starting with element 'price'. One of '{quantity}' is expected.
```

Corrected: PASS.

### .NET 8.0.33 · System.Xml.Schema

```text
The element 'order' has invalid child element 'price'. List of possible elements expected: 'quantity'.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

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

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
Unexpected child with tag 'price' at position 1. Tag 'quantity' expected.
```

Corrected: PASS.

Saxon EE was not available; no measured Saxon wording is claimed.

[All parser codes](https://xsdhub.com/learn#parser-error-codes)
[Download engine evidence](https://xsdhub.com/parser-error-examples/engine-evidence.json)
