# The required attribute is missing

Source: https://xmlvalid.com/errors/required-attribute-is-missing

> A required attribute is missing from an element.

The message, as .NET reports it: `The required attribute 'currency' is missing.`

## Why it happens

- The attribute is declared `use="required"` and the document leaves it out.
- Serialized output: `XmlSerializer` leaves out an `[XmlAttribute]` property that is `null`.

## How to fix it

- Add the attribute with a valid value. The message doesn't name the element: use the line and position of the validation event.
- .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 [The attribute is required but missing](https://xmlvalid.com/errors/attribute-is-required-but-missing): `Element 'order': The attribute 'currency' is required but missing.`

## Example that fails

```xml
<order>
  <id>A-1</id>
  <qty>1</qty>
</order>
```

## Fixed

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