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.

  • 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.
  • 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