# The element is not declared

Source: https://xmlvalid.com/errors/element-is-not-declared

> An element, usually the root, is not declared in the schema for its namespace.

The message, as .NET reports it: `The 'invoice' element is not declared.`

## Why it happens

- The wrong schema for this document, or a root element whose name is misspelt.
- A schema version that doesn't have the element yet, or declares it only locally inside another element.
- For an element in a namespace, .NET adds it: `'invoice' in namespace 'urn:…'`.

## How to fix it

- Check that the element's name matches a global `xs:element` of the schema. Mind the quieter variant: when no schema in the set has the element's namespace at all (a missing or different `xmlns`), .NET only warns, *Could not find schema information for the element*, and without `XmlSchemaValidationFlags.ReportValidationWarnings` the document passes without being checked.
- .NET throws an `XmlSchemaValidationException` at the first schema error unless `XmlReaderSettings.ValidationEventHandler` is set, which then receives every one with its line and position. A well-formedness error is an `XmlException` and ends reading whatever the settings.

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