XSD facet
enumeration
A closed list of permitted values, compared in the value space — so 01 and 1 are the same number.
Each enumeration facet contributes one permitted value, and the value must equal one of them. Comparison happens in the value space rather than the lexical one, which matters for anything numeric or whitespace-processed.
On an xs:decimal an enumeration of 1 accepts '1.0' and '01'. On an xs:token an enumeration of 'gold' accepts ' gold '. Both are correct and both surprise people.
- Lexical space
- One permitted value per facet.
- Derives from
- Primitive type
- Category
- Constraining facets
What catches people out
- Comparison is by value, not by text. On a numeric type '01' equals '1'.
- On a whitespace-collapsed type the value is collapsed before comparison, so surrounding spaces are accepted.
- You cannot enumerate on xs:boolean in a useful way, and enumerating floats is unreliable because NaN never matches.
The schema used
This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="t"><xs:restriction base="xs:token"><xs:enumeration value="gold"/><xs:enumeration value="silver"/></xs:restriction></xs:simpleType>
<xs:element name="v" type="t"/>
</xs:schema>Related
- patternA regular expression the whole value must match — anchored implicitly, and in XSD's own dialect rather than PCRE.
- xs:tokenA string trimmed of leading and trailing whitespace, with internal runs collapsed to one space. The right type for most identifiers.
- xs:decimalAn exact decimal number with arbitrary precision — and no exponent notation, which is the usual reason a value is rejected.
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.