Name

xs:enumeration — Allows you to specify a list of values as the only acceptable values for a given type

Applies to

All datatypes except xs:boolean

Attributes

value

Any simple type containing values consistent with the datatype for which they are being enumerated

Operation

Unlike the other facets, the enumeration element is used repeatedly within an xs:restriction element to specify allowed values. For example, to specify a type that contains the pigment primary colors red, blue, and yellow, you might write:

<xs:simpleType name="pigmentPrimaries">
  <xs:restriction base= "xs:token">
    <xs:enumeration value="red" />
    <xs:enumeration value="blue" />
    <xs:enumeration value="yellow" />
  </xs:restriction>
</xs:simpleType>

If someone confused his light primaries with his pigment primaries and tried to enter green, the validator would reject that value.

This facet cannot be fixed. Types derived from an enumerated type must be defined as subsets of the enumerated possibilities of the original type.

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.