Schemas and validity
Facet
A constraint that narrows a simple type: a length, a range, a regular expression, a list of permitted values.
Facets are how a schema says something specific about a value rather than merely naming its kind. xs:string becomes a product code with a pattern facet; xs:integer becomes a rating with minInclusive and maxInclusive.
Which facets apply depends on the base type — you cannot put a length facet on a number — and they compose, so a type may carry several. When one fails, the validator names the facet, which is the most useful diagnostic in the whole language.
- Defined in
- XSD 1.0 §4.3
- Category
- Schemas and validity
- Also written
- constraining facet, xs:pattern, xs:enumeration
Shown, not asserted
All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.
Facets are what make a type specific: unfaceted xs:string accepts anything.
schema.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="v" type="xs:string"/> </xs:schema>value ZZ-99999What the engine returns
Valid asxs:string.The value's kind is still checked first — a facet cannot rescue the wrong type.
schema.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="v" type="xs:integer"/> </xs:schema>value 1.5What the engine returns
Invalid asxs:integer.
What catches people out
- XSD regular expressions are anchored: the pattern must match the whole value, and there is no need for ^ or $.
- Facets apply to the whitespace-processed value, so a leading space may already be gone by the time a pattern is checked.
- An enumeration on a numeric type compares values, not strings: 1.0 and 1 are the same enumerated value.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- DatatypespatternThe regular-expression facet, with literals put through the validator.
- DatatypesenumerationThe fixed-list facet.
- Schema errorsThe value is not accepted by the patternThe message a failing pattern produces.
- Schema errorsThe value is not an element of the setAnd the one a value outside an enumeration produces.
Related terms
- Simple typeA schema type whose values are text with no child elements and no attributes — a string, a number, a date, or a restriction of one.
- XML Schema (XSD)The W3C schema language: a grammar written in XML itself, with datatypes, namespaces and a type system.
- ValidA well-formed document that also conforms to a declared grammar — a DTD, an XSD schema or a RELAX NG grammar.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.