January 2003
Beginner to intermediate
1200 pages
23h 42m
English
Besides using sequences, you can use choices in DTDs. A choice lets you specify that one of a number of elements will appear at that particular location. Here's how a choice specifying one of the elements <a> or <b> or <c> looks: (a | b | c). When you use this expression, the XML processor knows that exactly one of the <a> or <b> or <c> elements can appear.
I'll put choices to work in an example now. In this case, I'll specify that the <ITEM> element must enclose a <PRODUCT> element, a <NUMBER> element, and exactly one element from the list <PRICE>, <CHARGEACCT>, and <SAMPLE>:
<?xml version = "1.0" standalone="yes"?> <!DOCTYPE DOCUMENT [ <!ELEMENT DOCUMENT (CUSTOMER)*> <!ELEMENT CUSTOMER (NAME,DATE,ORDERS)> <!ELEMENT ... |