Data Type FacetsĀ
Simple types (both built-in and derived) have facets. A facet is a single defining aspect that helps determine the set of values for a simple type. For example, length, minInclusive, and maxInclusive are common facets for the built-in data types. All of the facets for a simple type define the set of legal values for that simple type.
A facet is defined as an element. Each facet element has a fixed attribute that is a Boolean value. When a simple type is defined, you can prevent derivatives of that type from modifying the value of specified facets. To prevent modification of a facet, add the fixed attribute to the facet and set its value to true.
Facets can only appear once in a type definition except for enumeration and pattern facets. Enumeration and pattern facets can have multiple entries and are grouped together.
Example
The following example shows a simple type with the fixed attribute set to true
which prevents the length from having a value other than 7
.
<xs:simpleType name="Postcode">
<xs:restriction base="xs:string">
<xs:length value="7" fixed="true"/>
</xs:restriction>
</xs:simpleType>
List of Constraining Facets
The constraining facets (facets that can be used to constrain the values of simple types), their descriptions, and the built-in data types that they apply to, are listed below.
- enumeration
Specified set of values. This constrains a data type to the specified values. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-enumeration.
- fractionDigits
Value with specific maximum number of decimal digits in the fractional part. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-fractionDigits.
- length
Number of units of length. Units of length depend on the data type. This value must be a nonNegativeInteger. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-length.
- maxExclusive
Upper bound value (all values are less than this value). This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-maxExclusive.
- maxInclusive
Maximum value. This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-maxInclusive.
- maxLength
Maximum number of units of length. Units of length depend on the data type. This value must be a nonNegativeInteger. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-maxLength.
- minExclusive
Lower bound value (all values are greater than this value). This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-minExclusive.
- minInclusive
Minimum value. This value must be the same data type as the inherited data type. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-minInclusive.
- minLength
Minimum number of units of length. Units of length depend on the data type. This value must be a nonNegativeInteger. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-minLength.
- pattern
Specific pattern that the data type's values must match. This constrains the data type to literals that match the specified pattern. The pattern value must be a regular expression. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-pattern.
- totalDigits
Value with specific maximum number of decimal digits. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-totalDigits.
whiteSpace
Value must be one of preserve, replace, or collapse. The whiteSpace facet cannot be changed for most numeric data types. For more information, see the W3C XML Schema Part 2: Datatypes Recommendation at http://www.w3.org/TR/2001/REC-xmlschema-2-20010502\#element-whiteSpace.preserve
No normalization is performed; the value is not changed for element content as required by the W3C XML 1.0 Recommendation.
replace
All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage return) are replaced with #x20 (space).
collapse
After the processing implied by replace, contiguous sequences of #x20s are collapsed to a single #x20, and leading and trailing #x20s are removed.
See Also
Reference
XML Data Types Reference
Primitive XML Data Types
Derived XML Data Types