Enumerations

<<< Here's the <wind> part of the weather report:

  <wind>
     <direction>NNW</direction>
     <speed>5</speed>
  </wind>

The RELAX specification for the <wind> is as follows:

    <elementRule role="wind">
        <sequence>
            <ref label="direction" occurs="?" />
            <ref label="speed"/>
        </sequence>
    </elementRule>
    <tag name="wind"/>

The only thing special about this is in the reference to the <direction> element. The occurs="?" means that this element can occur either zero times or exactly one time. (This makes sense, since a wind speed of zero doesn't have a direction.)

The <direction> element must be one of the sixteen compass directions. The RELAX <enumeration> element lets you specify this:

    <elementRule role="direction" type="string">
        <enumeration value="N"/> <!-- North -->
        <enumeration value="NNE"/> <!-- North by NorthEast -->
        <enumeration value="NE"/> <!-- NorthEast -->
        <!-- and so on -- >
    </elementRule>
    <tag name="direction"/>

Finally, the specification of the the <speed> element must require the value to be an integer greater than or equal to zero.

    <elementRule role="speed" type="nonNegativeInteger"/>
    <tag name="speed"/>

On the next page, you can see the entire RELAX document. >>>

  1. Validating XML with RELAX
  2. Validity and the DTD
  3. Validity and RELAX
  4. Specifying Elements
  5. Making Validation More Specific
  6. Further Specifications
  7. Enumerations
  8. The Big Picture
  9. Summary