# cvc-elt.1.a: Cannot find the declaration of element

Source: https://xmlvalid.com/errors/cvc-elt-1-a

> The document's root element is not declared in the schema it is validated against.

The message, as Java reports it: `cvc-elt.1.a: Cannot find the declaration of element 'invoice'.`

## Why it happens

- A namespace mismatch: the schema has a `targetNamespace` and the document's root has no `xmlns`, or a different one. This is by far the most common cause.
- The wrong schema for this document, or a schema whose root element is declared in another file it imports.
- The root element is declared only locally, inside another element, not as a global `xs:element`.

## How to fix it

- Compare the root element's name and namespace with the global elements of the schema: they must match exactly. Add the namespace declaration the schema expects to the root element, or validate with the right schema.
- 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 [No matching global declaration available for the validation root](https://xmlvalid.com/errors/no-matching-global-declaration): `Element 'invoice': No matching global declaration available for the validation root.`

## Example that fails

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

## Fixed

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