Value constraints refine a simple type by defining limits on the values that it can represent.
It is often useful to be able to constrain the values that an element can take, perhaps to ensure that messages conform to business rules. This topic describes how value constraints can be added to a simple type in order to constrain the values of all elements that are based on the simple type.
The value constraints that are discussed here are modeled by XML Schema facets, and are associated with a simple type.
Length constraints can be applied to simple types that are derived from xsd:hexBinary, xsd:base64Binary or xsd:string (including built in schema types such as xsd:normalisedString).
Length constraints are inherited from ancestor types, and any length constraints that are defined for a simple type must not relax the constraints that are imposed by any of its ancestor types. For example, a type 'longString' (Max Length=100) cannot be derived from a type 'shortString' (Max Length=10).
Range constraints are inherited from ancestor types, and any range constraints that are defined for a simple type must not relax the constraints that are imposed by any of its ancestor types. For example, a type 'largeNumber' (Max Inclusive=100) cannot be derived from a type 'smallNumber' (Max Inclusive=10).
The message model does not allow exclusive constraints to be applied to non-integral types (float, decimal, double, dateTime, and so on).
Enumeration constraints are inherited from ancestor types, and any set of enumeration constraints that are defined for a simple type must not increase the range of allowed values. For example, a type 'AllColors' (with enumerations for all colors of the rainbow) cannot be derived from a type 'MonoColors' (with enumerations for 'black' and 'white' only).
Precision constraints are inherited from ancestor types, and any precision constraints that are defined for a simple type must not relax the constraints that are imposed by any of its ancestor types. For example, a type 'veryPrecise' (Fraction Digits=10) cannot be derived from a type 'notVeryPrecise' (Fraction Digits=1).
As with all value constraints, a simple type can inherit pattern constraints from the simple type on which it is based. In this case, the set of pattern constraints that are contributed by each ancestor type must be satisfied, as well as the set that is contributed by the simple type itself. In other words, the sets of pattern constraints from each level in the type hierarchy are combined using Boolean AND.
Pattern constraints can only be applied to simple types that are derived from xsd:string.