Inclusive vs Exclusive Facets in XML Schema
In XML Schema Definition (XSD), boundary facets define the allowable range of values for ordered data types such as integers, decimals, dates, and times. The fundamental difference between inclusive and exclusive facets lies in whether the specified threshold value is accepted as valid: inclusive facets permit the exact boundary value, whereas exclusive facets require values to strictly exceed or stay below the boundary.
The Four Boundary Facets
XML Schema provides four primary facets to control minimum and maximum thresholds:
xs:minInclusive: Defines the lower bound where the specified value is included (greater than or equal to, \(\ge\)).xs:maxInclusive: Defines the upper bound where the specified value is included (less than or equal to, \(\le\)).xs:minExclusive: Defines the lower bound where the specified value is excluded (strictly greater than, \(>\)).xs:maxExclusive: Defines the upper bound where the specified value is excluded (strictly less than, \(<\)).
Inclusive Boundary Facets
Inclusive facets are used when the threshold itself is a valid, allowable input.
Example: Defining a Percentage (0 to 100)
<xs:simpleType name="PercentageType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>- Valid values:
0,50,100 - Invalid values:
-1,101
In this example, both 0 and 100 pass
validation because the boundaries are inclusive.
Exclusive Boundary Facets
Exclusive facets are used when a value must approach a boundary but cannot equal it.
Example: Strictly Positive Numbers Below 100
<xs:simpleType name="StrictPositiveUnderHundred">
<xs:restriction base="xs:integer">
<xs:minExclusive value="0"/>
<xs:maxExclusive value="100"/>
</xs:restriction>
</xs:simpleType>- Valid values:
1,50,99 - Invalid values:
0,100,-5,105
Here, 0 and 100 fail validation because
exclusive boundaries omit the specified limits.
Summary Comparison
| Facet | Mathematical Equivalent | Boundary Included? | Common Use Case |
|---|---|---|---|
xs:minInclusive="X" |
Value >= X |
Yes | Minimum age requirements, zero-based indexes |
xs:maxInclusive="X" |
Value <= X |
Yes | Maximum percentage, capped ratings |
xs:minExclusive="X" |
Value > X |
No | Non-zero positive quantities, strictly future dates |
xs:maxExclusive="X" |
Value < X |
No | Upper bounds where limit represents an overflow state |
These facets can be combined (e.g., using
xs:minInclusive with xs:maxExclusive) to
create half-open ranges, which are common when validating continuous
domains like timestamps and floating-point measurements.