RELAX NG by Eric van der Vlist will be published by O'Reilly & Associates (ISBN: 0596004214)

You are welcome to use our annotation system to give your feedback.


Exclusions

What if, instead of giving a list of values which are allowed, I wanted to give a list of values which are forbidden? The except pattern serves precisely this purpose.

To exclude the value "0836217462" from the possible ISBN numbers, we would write:

    <element name="isbn">
     <data type="token">
      <except>
       <value>0836217462</value>
      </except>
     </data>
    </element>

Or, using the compact syntax:

   element isbn {token - "0836217462"}

Although this looks simple, we must note that the type can be defined at two different levels here: it must be defined in the data pattern and may also be defined in the value pattern; these two definitions have a different meaning. The type attached to the data pattern defines a validation performed on the text node while the type attached to the value pattern defines how the value should be interpreted and which whitespace processing should be performed.

In our example, both are token types and values such as " 0836217462 " would be excluded as well as "0836217462". The token type, as noted above, normalizes whitespace before making comparisons. The two datatypes could also be mixed, as in:

    <attribute name="available">
     <data type="token">
      <except>
       <choice>
        <value type="string">available</value>
        <value type="string">checked out</value>
        <value type="string">on hold</value>
       </choice>
      </except>
     </data>
    </attribute>

Or, using the compact syntax:

 attribute available {token -(string "available"|string "checked out"|string
"on hold")}

In this case, the first control would be done on the datatype token and the comparison would use the datatype string. To push this a little further, we'll examine what happens when we use it with datatypes.

     <data type="integer">
      <except>
       <choice>
        <value type="integer">1</value>
       </choice>
      </except>
     </data>

Or, using the compact syntax:

integer -(integer "1")

In this case both cases are performed on integers. This accepts any integer except values representing "1" as an integer. ("1" and also "01" or "001" are forbidden.)

Now, consider:

     <data type="integer">
      <except>
       <choice>
        <value>1</value>
       </choice>
      </except>
     </data>

Or, using the compact syntax

 integer -("1")

This still accepts any integer except "1". However, if "1" appears, it is considered (by default) as a token, so "1" isn't forbidden any longer.


You are welcome to use our annotation system to give your feedback.
[Annotations for this page]
All text is copyright Eric van der Vlist, Dyomedea. During development, I give permission for non-commercial copying for educational and review purposes. After publication, all text will be released under the Free Software Foundation GFDL.