# cvc-complex-type.3.2.2 / cvc-complex-type.4: attributes

Attribute errors have two opposite directions. cvc-complex-type.3.2.2 says an attribute appears where the effective complex type does not permit it. cvc-complex-type.4 says a required attribute is absent. The schema declaration decides which condition applies.

## Literal meaning

The first pair writes colour while the type declares color. Correcting the attribute name preserves its blue value. The second pair leaves out id even though use="required" requires it; adding id="A1" satisfies that declaration. A present but empty attribute is a different case and can still fail its own datatype.

## Three common causes

1. The attribute name, case or namespace is wrong. A familiar field label does not guarantee that its expanded attribute name matches the declaration.
2. A serializer drops required attributes when a source value is null. Check the export rule and data availability instead of changing use to optional automatically.
3. The document uses an attribute from a different complex type or extension. An attribute allowed on a sibling element may be prohibited on this parent or schema version.

## Repair

Locate the effective complex type, including any base type, restriction and attribute groups. Compare each present attribute with its declaration, then inspect use="required" entries for omissions. If a wildcard is involved, check its namespace and processing rules separately. Repair spelling and source mappings, and rerun the whole element to catch value failures after presence checks pass.

## Namespace checks

Default namespaces apply to unprefixed element names but not ordinary unprefixed attribute names. Adding xmlns to item does not qualify id. For a qualified attribute declaration, bind and use the correct prefix on that attribute; for an unqualified declaration, an accidental prefix can turn an otherwise correct name into an undeclared attribute.

Keep these two specimens separate when reproducing a production report. Renaming a misspelled required attribute can clear both “not allowed” and “must appear” diagnostics with one edit, but adding a second attribute without removing the wrong one leaves the undeclared-attribute failure behind. Never remove a required identifier just because a different attribute message appeared first.

## Undeclared attribute / cvc-complex-type.3.2.2 — Broken

```xml
<item colour="blue"/>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="item">
    <xs:complexType>
      <xs:attribute name="color" type="xs:string"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
```

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

## Undeclared attribute / cvc-complex-type.3.2.2 — Corrected

```xml
<item color="blue"/>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="item">
    <xs:complexType>
      <xs:attribute name="color" type="xs:string"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
```

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

### Apache Xerces-J 2.12.2

```text
cvc-complex-type.3.2.2: Attribute 'colour' is not allowed to appear in element 'item'.
```

Corrected: PASS.

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

```text
The 'colour' attribute is not declared.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

```text
Element 'item', attribute 'colour': The attribute 'colour' is not allowed.
```

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
'colour' attribute not allowed for element
```

Corrected: PASS.

## Missing attribute / cvc-complex-type.4 — Broken

```xml
<item/>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="item">
    <xs:complexType>
      <xs:attribute name="id" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
```

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

## Missing attribute / cvc-complex-type.4 — Corrected

```xml
<item id="A1"/>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="item">
    <xs:complexType>
      <xs:attribute name="id" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
</xs:schema>
```

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

### Apache Xerces-J 2.12.2

```text
cvc-complex-type.4: Attribute 'id' must appear on element 'item'.
```

Corrected: PASS.

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

```text
The required attribute 'id' is missing.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

```text
Element 'item': The attribute 'id' is required but missing.
```

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
missing required attribute 'id'
```

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)
