XML technologies / XML Schema / XML Schema element reference / xs:maxLength

(Excerpt from “XML Schema” by Eric van der Vlist)

Facet specifying a maximum length.

<xs:maxLength
    fixed = xs:boolean : "false"
    id = xs:ID
    value = xs:nonNegativeInteger
    {beliebige Attribute mit einem Nicht-Schema-Namensraum}
    >
    Content: (xs:annotation?)
</xs:maxLength>

May occur within: xs:restriction (simple type), xs:restriction (simple content)

May be used as a facet for: xs:anyURI, xs:base64Binary, xs:ENTITIES, xs:ENTITY, xs:hexBinary, xs:ID, xs:IDREF, xs:IDREFS, xs:language, xs:Name, xs:NCName, xs:NMTOKEN, xs:NMTOKENS, xs:normalizedString, xs:NOTATION, xs:QName, xs:string, xs:token

Description

xs:maxLength specifies the maximum permitted length in a type-dependent unit. For most data types, the unit is the character defined in XML 1.0, namely Unicode characters defined by ISO/IEC 10646, possibly represented with more than eight bits. Exceptions are binary data types (xs:hexBinary and xs:base64Binary), whose lengths count binary-data bytes of eight bits, and list types, whose lengths count list items.

xs:maxLength restricts value space. In practice, it is checked after whitespace replacement and collapsing as defined by facet xs:whitespace.

Restrictions

This is a logical length, often unrelated to the storage space a value needs.

It is forbidden to define both xs:maxLength and xs:length within one restriction step. Although unstated in the recommendation, defining several xs:maxLength facets in one step is also meaningless.

Within one restriction step, xs:maxLength also interacts with xs:minLength, since inconsistent values produce types with empty value spaces.

xs:maxLength must restrict its base type’s value space, and its value must be smaller than the base type’s xs:maxLength value, if defined.

Although unstated in the recommendation, an interaction exists between xs:minLength and xs:length. xs:minLength should not be defined if xs:length is defined for its base type.

Fixing facet xs:maxLength does not fix facet xs:length . Use two restriction steps to fix both, since applying them in the same step is forbidden.

Example

<xs:simpleType name="binaryImage">
    <xs:restriction base="xs:hexBinary">
        <xs:maxLength value="1024"/>
    </xs:restriction>
</xs:simpleType>

Attributes

fixed
If the value is true, this facet’s value cannot be modified in further restrictions.

id
Element ID according to W3C XML Schema.

value
Facet value.

   

 

 

 

back to top