XML Schema Constraining Facets
The XML Schema Part 2: Datatypes specification defines both
fundamental facets and constraining
facets. Fundamental facets (equal, ordered, bounded,
cardinality, and numeric) are built into the definitions of the
predefined datatypes and aren’t available for you to use in creating
your own schemas. Constraining facets, on the other hand, allow you to
specify more exactly the values or kinds of values may be stored in
your schema components. Applying these facets in xs:restriction
elements allows you to create
more precise types than those that come built into XML Schema itself.
Many of these facets apply only to particular types—for instance,
xs:fractionDigits
wouldn’t make
much sense applied to strings.
All facet elements may contain xs:annotation
child elements and have
attributes outside the XML Schema namespace. They also share the
fixed
and id
attributes. When the fixed
attribute is set to true
, the given facet cannot be modified
during later restriction. The id
attribute is useful if you’re creating schemas automatically and need
guaranteed unique identifiers on every component.
Also, some facets cannot be applied simultaneously with others.
If you need to set both, you’ll need to use two separate xs:restriction
elements.
Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.