# The prefix for element is not bound

Source: https://xmlvalid.com/errors/prefix-for-element-is-not-bound

> An element uses a namespace prefix that no xmlns declaration defines.

The message, as Java reports it: `The prefix "inv" for element "inv:invoice" is not bound.`

## Why it happens

- The `xmlns:prefix="…"` declaration is missing, misspelt, or on an element that does not enclose this one.
- A fragment cut out of a larger document, whose namespace declarations were on an ancestor left behind.

## How to fix it

- Declare the prefix on the element or one of its ancestors, usually the root: `xmlns:inv="urn:…"` with the namespace the format defines. When extracting a fragment, serialize it with an XML API, which copies the declarations it needs.
- 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 [Namespace prefix is not defined](https://xmlvalid.com/errors/namespace-prefix-is-not-defined): `Namespace prefix inv on invoice is not defined`

## Example that fails

```xml
<inv:invoice/>
```

## Fixed

```xml
<inv:invoice xmlns:inv="urn:example:invoice"/>
```
