Using DTDs

According to textbooks, DTDs are strange creatures. Let's use a simple example to describe. Take the following:

<!DOCTYPE letter [
    <!ELEMENT letter (to, from, subject, message)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT subject (#PCDATA)>
    <!ELEMENT message (#PCDATA)>

The first line declares that this is a DTD for XML documents with the root element letter. The letter-element is declared as consisting of four elements. These elements must appear in the order described in the comma separated list

<!ELEMENT letter (to, from, subject, message)>

The parentheses hold the rules for the content, the order, and the number of each element allowed by the DTD. In the list of elements parentheses may be inserted to create groups of occurences. Special characters reminiscing wild card characters from regular expressions in UNIX or programming languages are used to define number of occurences of individual elements or groups of elements. the following table illuminates the use of the special characters and their meaning:

?
<!ELEMENT letter (to,from,subject,message,sig?)>

None or one sig.

+
<!ELEMENT letter (to,from,subject,message,sig+)>

One or more sigs.

*
<!ELEMENT letter (to,from,subject,message,sig*)>

Zero or more sig.

|
<!ELEMENT letter (to,from,subject,message,sig|ps)>

End letter with sig or ps.

()
<!ELEMENT letter ((to,from,subject,message)|#PCDATA)>

Parentheses define groups of elements. Here letter has a group as defined or just text (parsed character data).

Look at the possibilities:

Example 40.1. 
  1. <!ELEMENT group (projectmanager, member, menber+)>
  2. <!ELEMENT class ((group, member+)+)>
  3. <!ELEMENT project (task|#PCDATA)>
  4. <!ELEMENT table (tr, tr)>
  5. <!ELEMENT tr (td+)>