- 73 -
For this declaration, a legitimate XML representation would be:
…
Other legal answers would be only choice2 or choice3. Thus,
...
...
would be unacceptable as the declaration specifies
only
one occurrence of the elements
specified can occur. Similarly,
…
is not allowed because choice4 has not been specified in the list of acceptable choices.
Scenario: Specifying a Subelement That Occurs Once or Not at All
Suppose you create an online form that requires information from a user, some of which
is optional. For example, say you’re asking for personal information and that title is not a
required field, while the user’s name and e-mail address is required. You only want one
occurrence of each field and you want it in a particular order. Here’s how to specify it:
According to this, the parser thinks an element of type user consists of one element of
type name, one element of type e-mail, and optionally one element of type title.
Here’s what a valid user element looks like:
Austin Sours
austins@being_silly.com
International Man of Tartness
An equally valid user could look like this:
Austin Sours
austins@being_silly.com
A nonvalid user element would be:
Austin Sours
- 74 -
international man of tartness
This example is not valid because the necessary e-mail_address element is missing.