You are here:About>Computing & Technology>Web Design / HTML> XML> DTDs> What is a DTD
About.comWeb Design / HTML
Newsletters & RSSEmail to a friendSubmit to Digg

What is a DTD

From Jennifer Kyrnin,
Your Guide to Web Design / HTML.
FREE Newsletter. Sign Up Now!

Part 1: Document Type Definitions and Valid XML

As you learned in another article, a DTD is the grammar of an XML page. It is an acronym that stands for Document Type Definition. It contains the elements, attributes, entities, and notations used in the XML document.

Valid XML

XML is really a markup language to create other markup languages, and the DTD is the tool you use to create and describe your language. Once a DTD is created and a document written based on that DTD, the document is then compared to the DTD. This is called validation. If your XML document follows the rules listed in the DTD, then the document is said to be valid. XML documents that don't follow the rules in their DTDs are called invalid.

For example, while we haven't gone over the structure of a DTD yet, here is part of a simple one. It states that there is a root element called "family" that has two possible elements within it: "parent" and "child":

<!DOCTYPE family [
  <!ELEMENT parent (#PCDATA)>
  <!ELEMENT child (#PCDATA)>
]>

If you were to write an XML document based upon that DTD, you could write:

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE family [
  <!ELEMENT parent (#PCDATA)>
  <!ELEMENT child (#PCDATA)>
]>

<family>
<parent>Judy</parent>
<parent>Layard</parent>
<child>Jennifer</child>
<child>Brendan</child>
</family>

This would be a valid XML document. But if I added extra text outside of the <parent> or <child> tags, the document would be invalid until I changed the DTD:

...
<family>
This is my family:
<parent>Judy</parent>
<parent>Layard</parent>
<child>Jennifer</child>
<child>Brendan</child>
</family>

Next Page > Elements, Entities, Attributes, and Notations > Page 1, 2, 3

Previous Features

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.