1. Home
  2. Computing & Technology
  3. Web Design / HTML

What is a DTD

Part 3: A Sample DTD

By Jennifer Kyrnin, About.com

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

Previous Features

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. XML
  5. DTDs
  6. What is a DTD: A Sample DTD

©2008 About.com, a part of The New York Times Company.

All rights reserved.