Repeated Elements
May 3, 1999
What do you think the following DTD snippet would imply?
<!ELEMENT CONTACT (NAME, EMAIL+)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT EMAIL (#PCDATA)>
Take a look at the regular expression
character chart a couple
of frames back and guess.
That is right! It would mean that a CONTACT element could have
a NAME element followed by one or more EMAIL elements. Thus,
the following XML would be valid.
<CONTACT>
<NAME>Jim Sanger</NAME>
<EMAIL>sanger@sanger.com</EMAIL>
<EMAIL>sanger@yahoo.com</EMAIL>
<EMAIL>sanger@netscape.com</EMAIL>
</CONTACT>
What about the following?
<CONTACT>
<NAME>Jim Sanger</NAME>
</CONTACT>
Well that would be invalid because the "+" sign specifies "one
or more". To allow for "zero or more" occurrences, you must
use a "*" such as:
<!ELEMENT CONTACT (NAME, EMAIL*)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT EMAIL (#PCDATA)>
Ordering Child Elements
Introduction to XML For Web Developers | Table of Contents
Grouping Elements
|