Introduction to XML | Defining XML Structures with DTD | Choosing One of Multiple Elements

DTD can define a choice where one of several elements must appear. Separate alternatives with |:

<!ELEMENT element-name (child1 | child2 | ...)>

For example, a contact contains one of home, office, or mobile:

<!ELEMENT contact (home | office | mobile)>

A document using this rule can be defined as follows:

<!DOCTYPE customers[
  <!ELEMENT customers (customer+)>
  <!ELEMENT customer (name, gender, hobby*, contact)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT gender (#PCDATA)>
  <!ELEMENT hobby (#PCDATA)>
  <!ELEMENT contact (home | office | mobile)>
  <!ELEMENT home (#PCDATA)>
  <!ELEMENT office (#PCDATA)>
  <!ELEMENT mobile (#PCDATA)>
]>

You can also place the choice directly in the parent element:

<!ELEMENT customer (name, gender, hobby*, (home | office | mobile))>

In this case, the fourth child of customer is one of home, office, or mobile.