Enumerations

An enumeration is a choice between several values. Enumerations are thus written in RELAX NG by combining the choice pattern with the value pattern. In our library, a good candidate for an enumeration is the available attribute, which can be defined as:

<attribute name="available">
 <choice>
  <value>available</value>
  <value>checked out</value>
  <value>on hold</value>
 </choice>
</attribute>

or:

attribute available {"available"|"checked out"|"on hold"}

This definition validates values such as "available“, "checked out“, and "on hold“. It also validates values such as " available “, "checked out “, or even " on hold " with multiple spaces, tabs or carriage returns between "on" and "hold" or "checked" and "out“. You will see the reason for this behavior—and how to change it if needed—in the next section.

Get RELAX NG 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.