Using Different Types in Each Value
In our previous schema, we were required to define the type for each
value pattern:
attribute available {string "available"|string "checked out"|string
"on hold"}This example doesn’t show all that RELAX NG is capable of. There is no rule that keeps you from using attributes that have different datatypes in an enumeration. Thus, although this example shows an enumeration with datatypes that are all the same, you aren’t restricted to using attributes with all the same datatype in an enumeration.
This will become more interesting after Chapter 8 (when there will be more simple datatypes to work with), but you can write:
<attribute name="available"> <choice> <value type="string">available</value> <value type="token">checked out</value> <value type="string">on hold</value> </choice> </attribute>
or, in the compact syntax:
attribute available {
string "available"|
token "checked out"|
string "on hold"}This schema normalizes whitespace to check the value
checked
out, defined as
token, but doesn’t do any
normalization when examining the other two values
(available and on hold) defined
as string.
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