# cvc-complex-type.3.2.2: Attribute is not allowed to appear in element

Source: https://xmlvalid.com/errors/cvc-complex-type-3-2-2

> An element carries an attribute its type in the schema does not declare.

The message, as Java reports it: `cvc-complex-type.3.2.2: Attribute 'vat' is not allowed to appear in element 'order'.`

## Why it happens

- A misspelt attribute name or a different letter case.
- An attribute from a newer version of the format, validated against an older schema.
- A namespaced attribute (`xsi:`, `xml:lang`) the schema doesn't allow there.

## How to fix it

- Remove or rename the attribute, or validate against the schema version the document was written for. If the attribute is needed, declare it in the element's type (`xs:attribute`, or `xs:anyAttribute` for open content).
- Java's schema validation (`javax.xml.validation.Validator`, and JAXB or Spring on top of it) throws at the first error unless you set an `ErrorHandler` whose `error()` records the `SAXParseException` and carries on; each one has `getLineNumber()` and `getColumnNumber()`. A well-formedness error ends parsing whatever the handler does.

## The same problem in xmlvalid

libxml2, which xmlvalid validates with, reports it as [The attribute is not allowed](https://xmlvalid.com/errors/attribute-is-not-allowed): `Element 'order', attribute 'vat': The attribute 'vat' is not allowed.`

## Example that fails

```xml
<order currency="EUR" vat="20">
  <id>A-1</id>
  <qty>1</qty>
</order>
```

## Fixed

```xml
<order currency="EUR">
  <id>A-1</id>
  <qty>1</qty>
</order>
```
