cvc-maxLength-valid: Value with length is not facet-valid with respect to maxLength
A value is longer than its type allows.
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
xmlvalid validates with libxml2, which reports it as [facet 'maxLength'] The value exceeds the allowed length. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.
Element 'note': [facet 'maxLength'] The value has a length of '17'; this exceeds the allowed maximum length of '10'.
Example
Validated against order.xsd, below.
<order currency="EUR">
<id>A-1</id>
<qty>1</qty>
<note>far too long text</note>
</order>
<order currency="EUR">
<id>A-1</id>
<qty>1</qty>
<note>short</note>
</order>
order.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="qty" type="xs:int"/>
<xs:element name="status" type="Status" minOccurs="0"/>
<xs:element name="code" type="Code" minOccurs="0"/>
<xs:element name="note" type="Short" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="currency" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="Status">
<xs:restriction base="xs:string">
<xs:enumeration value="open"/>
<xs:enumeration value="paid"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Code">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]{3}-[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Short">
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>