# cvc-maxLength-valid: Value with length is not facet-valid with respect to maxLength

Source: https://xmlvalid.com/errors/cvc-maxlength-valid

> A value is longer than its type allows.

The message, as Java reports it: `cvc-maxLength-valid: Value 'far too long text' with length = '17' is not facet-valid with respect to maxLength '10' for type 'Short'.`

## Why it happens

- Text longer than the format allows: a name, an address line, a free-text note.
- Whitespace or a line break inside the element, which counts towards the length.

## How to fix it

- Shorten the value to the length in the message, or split it across the elements the format provides for longer text. *cvc-minLength-valid* and *cvc-length-valid* are the same check for a minimum and an exact length.
- 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 [[facet 'maxLength'] The value exceeds the allowed length](https://xmlvalid.com/errors/facet-length): `Element 'note': [facet 'maxLength'] The value has a length of '17'; this exceeds the allowed maximum length of '10'.`

## Example that fails

```xml
<order currency="EUR">
  <id>A-1</id>
  <qty>1</qty>
  <note>far too long text</note>
</order>
```

## Fixed

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