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.
RELAX NG supports the description of text nodes which are lists of whitespace-separated values using the list pattern. This is the only pattern which transforms the structure of the document at validation time by splitting text values into lists of values. The benefit of doing so is that within a list pattern, all the pattern constraining data values may be used combined with the compositors which will let us constrain the combination of these values.
If we use a list pattern without defining cardinality, we may not get what we expect. An attribute defined as:
<attribute name="see-also"> <list> <data type="token"/> </list> </attribute> |
or, using the compact syntax:
attribute see-also {list {token}} |
would not match a list of tokens (such as see-also="0345442695 0449220230 0449214044 0061075647 0061075612") but a list of exactly one token (such as see-also="0345442695"). This is because the list pattern splits the text value into a list of values and this list is then evaluated against the patterns which are included within the list pattern. If we want a list of any number of tokens, we must use a zeroOrMore pattern to express that:
<attribute name="see-also"> <list> <zeroOrMore> <data type="token"/> </zeroOrMore> </list> </attribute> |
Or, using the compact syntax:
attribute see-also {list {token*}} |
This would treat the see-also attribute as a list of tokens and wouldn't add any other constraints (this will of course be different when we will have more datatypes). We could have used other compositors in the list pattern exactly as we have used them in other contexts. To express that we want a list with between 1 to 4 tokens, we could say:
<attribute name="see-also"> <list> <data type="token"/> <optional> <data type="token"/> </optional> <optional> <data type="token"/> </optional> <optional> <data type="token"/> </optional> </list> </attribute> |
Or, using the compact syntax:
attribute see-also {list {token, token?, token?, token?}} |
That is certainly verbose but we have already seen that we have no other options for defining the number of occurrences with RELAX NG.
We could also constrain the values of these tokens, for instance, through an enumeration:
<attribute name="see-also"> <list> <oneOrMore> <choice> <value>0836217462</value> <value>0345442695</value> <value>0449220230</value> <value>0449214044</value> <value>0061075647</value> </choice> </oneOrMore> </list> </attribute> |
Or:
attribute see-also {list {("0836217462"|"0345442695"|"0449220230"|"0449214044"|"0061075647")+}} |
A final point to note is that the list mechanism gives us the ability to define different constraints for different members of a list. To illustrate this feature, we'll take another example. Let's say that we want to give the physical dimension of a book by giving each of its dimensions a unit, such as:
<book id="b0836217462" available="true" dimensions="0.38 8.99 8.50 inches"> |
In this case, we can define the dimensions attribute as:
<attribute name="dimensions"> <list> <data type="token"/> <data type="token"/> <data type="token"/> <choice> <value>inches</value> <value>cm</value> <value>mm</value> </choice> </list> </attribute> |
Or:
attribute dimensions {list {token, token, token, ("inches"|"cm"|"mm")}} |
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.