Exclusions
What if, instead of giving a list of allowed values, you want to give
a list of values that are forbidden? The
except
pattern serves precisely this purpose.
To exclude the value 0836217462 from the possible
ISBN numbers, 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 statement looks simple, 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 this example, both are token types, and values
such as " 0836217462
" are excluded as well as
"0836217462“.
The token type, as noted previously, normalizes
whitespace before making comparisons. The two datatypes can 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 is done on the datatype ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access