XSD Facets (Restrictions)

Facets narrow a base type to a specific range, length, pattern, or enumeration. They are defined inside <xs:restriction> elements and are the primary tool for constraining data values in XSD.

Syntax

xml-fundamentals
minInclusive / maxInclusive — numeric/date range
minExclusive / maxExclusive — exclusive bounds
minLength / maxLength / length — string length
pattern — regular expression
enumeration — allowed values list
whiteSpace — normalize/collapse/preserve

Example

xml-fundamentals
<!-- Integer 1-100 -->
<xs:restriction base="xs:integer">
  <xs:minInclusive value="1"/>
  <xs:maxInclusive value="100"/>
</xs:restriction>

<!-- Regex pattern -->
<xs:restriction base="xs:string">
  <xs:pattern value="[A-Z]{2}-\d{4}"/>
</xs:restriction>

<!-- Enumeration -->
<xs:restriction base="xs:string">
  <xs:enumeration value="active"/>
  <xs:enumeration value="inactive"/>
</xs:restriction>