Skip to main content
XMLDir

Search 261 pages — tools, formats, elements, namespaces, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

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 validates

Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.

  • gold

What does not

  • platinum

    Not in the enumerated list.

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.

schema.xsd
<?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>

Open the XSD validator

Related

All 29 datatypes and facets

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.