# cvc-minLength-valid / cvc-maxLength-valid: length bounds

These related facets place lower and upper bounds on the length measured by a simple datatype. They belong in one diagnostic guide because the repair starts with the same question: what does this type count, and at which processing stage?

## Literal meaning

The minimum example requires at least three characters: AB has length two and ABC has length three. The maximum example permits at most five characters: ABCDEF has length six and ABCDE has length five. Each pair has its own complete schema so neither boundary can mask the other during reproduction.

## Three common causes

1. The exporter truncates a field, omits part of an identifier or sends a placeholder shorter than the required minimum. Empty tags count as empty values for these string specimens.
2. The value contains extra whitespace or added formatting. The base datatype’s whitespace behavior decides whether those characters survive before the length facet runs.
3. The application counts the wrong units. String length, list item count and binary length are different measures; byte counts and UI character counters need not match the schema datatype.

## Repair

Find the restriction base and determine the units used by its length facets. Check inherited bounds as well as the immediate declaration. Test the exact boundary, one unit below and one above using the receiving validator. Repair the original field or contract mapping rather than padding an identifier with arbitrary characters or silently dropping meaningful content.

## Namespace checks

Neither tested boundary failure is repaired by adding a namespace: the code element already matches its declaration. A namespace issue is plausible only when the wrong declaration or schema version supplies unexpected bounds. Verify the effective type before assuming that the validator’s reported length is a browser character-counting bug.

The corrected short strings are demonstrations of boundary behavior, not instructions to truncate production data. For identifiers, truncation can create collisions; for names, padding can corrupt meaning. Keep the original data and resolve the mapping or schema agreement that explains the bound. The two transcripts below preserve each engine’s own length wording.

## Minimum length / cvc-minLength-valid — Broken

```xml
<code>AB</code>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="code">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:minLength value="3"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
```

[Open broken pair](https://xsdhub.com/?example=parser-minlength&variant=bad#workbench)

## Minimum length / cvc-minLength-valid — Corrected

```xml
<code>ABC</code>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="code">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:minLength value="3"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
```

[Open corrected pair](https://xsdhub.com/?example=parser-minlength&variant=good#workbench)

### Apache Xerces-J 2.12.2

```text
cvc-minLength-valid: Value 'AB' with length = '2' is not facet-valid with respect to minLength '3' for type '#AnonType_code'.
cvc-type.3.1.3: The value 'AB' of element 'code' is not valid.
```

Corrected: PASS.

### .NET 8.0.33 · System.Xml.Schema

```text
The 'code' element is invalid - The value 'AB' is invalid according to its datatype 'String' - The actual length is less than the MinLength value.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

```text
Element 'code': [facet 'minLength'] The value has a length of '2'; this underruns the allowed minimum length of '3'.
```

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
value length cannot be lesser than 3
```

Corrected: PASS.

## Maximum length / cvc-maxLength-valid — Broken

```xml
<code>ABCDEF</code>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="code">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="5"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
```

[Open broken pair](https://xsdhub.com/?example=parser-maxlength&variant=bad#workbench)

## Maximum length / cvc-maxLength-valid — Corrected

```xml
<code>ABCDE</code>
```

```xml
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="code">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="5"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
```

[Open corrected pair](https://xsdhub.com/?example=parser-maxlength&variant=good#workbench)

### Apache Xerces-J 2.12.2

```text
cvc-maxLength-valid: Value 'ABCDEF' with length = '6' is not facet-valid with respect to maxLength '5' for type '#AnonType_code'.
cvc-type.3.1.3: The value 'ABCDEF' of element 'code' is not valid.
```

Corrected: PASS.

### .NET 8.0.33 · System.Xml.Schema

```text
The 'code' element is invalid - The value 'ABCDEF' is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value.
```

Corrected: PASS.

### XSDHub libxml2/WASM 0.7.2

```text
Element 'code': [facet 'maxLength'] The value has a length of '6'; this exceeds the allowed maximum length of '5'.
```

Corrected: PASS.

### XSDHub xmlschema 4.3.1 · XSD 1.0

```text
value length cannot be greater than 5
```

Corrected: PASS.

Saxon EE was not available; no measured Saxon wording is claimed.

[All parser codes](https://xsdhub.com/learn#parser-error-codes)
[Download engine evidence](https://xsdhub.com/parser-error-examples/engine-evidence.json)
