DTDs are not difficult to write, but it is often easier to write an XML document first, and then define the DTD based upon what you wrote. For this example, I wrote an XML document based on a portion of a family tree. Once the document was finished, I wrote my DTD to match.
The XML Document
<?xml version="1.0" standalone="yes"?>
<family>
<title>My Family</title>
<parent role="mother">Judy</parent>
<parent role="father">Layard</parent>
<child role="daughter">Jennifer</child>
<image source="JENN" />
<child role="son">Brendan</child>
&footer;
</family>
The DTD
<!DOCTYPE family [
<!ELEMENT title (#PCDATA)>
<!ELEMENT parent (#PCDATA)>
<!ATTLIST parent role (mother | father) #required>
<!ELEMENT child (#PCDATA)>
<!ATTLIST child role (daughter | son) #required>
<!NOTATION gif system "image/gif">
<!ENTITY JENN system
"http://images.about.com/sites/guidepics/html.gif"
NDATA gif>
<!ELEMENT image empty>
<!ATTLIST image source entity #required>
<!ENTITY footer "Brought to you by Jennifer Kyrnin">
]>
First Page > What is a DTD > Page 1, 2, 3

