Ordering Child Elements
May 3, 1999
Consider the following DTD snippet....
<!ELEMENT CONTACT (NAME EMAIL)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT EMAIL (#PCDATA)>
In this case, we expect to see XML along the lines of:
<CONTACT>
<NAME>Jim Sanger</NAME>
<EMAIL>sanger@sanger.com</EMAIL>
</CONTACT>
Alternatively, the following code would be valid:
<CONTACT>
<EMAIL>sanger@sanger.com</EMAIL>
<NAME>Jim Sanger</NAME>
</CONTACT>
Notice that since we simply listed the children of CONTACT
as a space delimited list, we do not specify any order in
which the children should appear. Had we used a comma to
separate the list, we would be forcing an order. Thus
if we redefined our DTD to use:
<!ELEMENT CONTACT (NAME, EMAIL)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT EMAIL (#PCDATA)>
Then the following XML would be valid:
<CONTACT>
<NAME>Jim Sanger</NAME>
<EMAIL>sanger@sanger.com</EMAIL>
</CONTACT>
but the following XML would be invalid because the EMAIL
element would not be allowed to precede the NAME element.
<CONTACT>
<EMAIL>sanger@sanger.com</EMAIL>
<NAME>Jim Sanger</NAME>
</CONTACT>
Defining Elements and their Children
Introduction to XML For Web Developers | Table of Contents
Repeated Elements
|