Search code examples
xmlxsdxsd-validationxml-validation

Error: The maxLength facet is not applicable to types derived from xs:integer


When I try

<xsd:simpleType>
    <xsd:restriction base="xsd:nonNegativeInteger">
        <xsd:maxLength value="35"/>
        <xsd:minLength value="1"/>
    </xsd:restriction>
</xsd:simpleType>

I get the error

The maxLength facet is not applicable to types derived from xs:integer

How can I achieve a positive integer with minLength and maxLength?


Solution

  • To allow integers between 1..35, inclusive:

    <xsd:simpleType>
        <xsd:restriction base="xsd:nonNegativeInteger">
            <xsd:minInclusive value="1"/>
            <xsd:maxInclusive value="35"/>
        </xsd:restriction>
    </xsd:simpleType>
    

    To allow integers with 1..35 digits:

    <xsd:simpleType>
        <xsd:restriction base="xsd:nonNegativeInteger">
            <xsd:pattern value="\d{1,35}"/>
        </xsd:restriction>
    </xsd:simpleType>