Workshops --> XML --> Demo --> dtd.html
SLIS@IU logo

L595 XML@IU logo

Creating DTDs

What is a DTD?

It is a set of rules that structure an XML document and tell the processor how to parse and display it

A DTD defines the components of an XML document and specifies conditions for their use

It determines what can be placed in these components

It determines what is required and what is optional in the document

It defines the order in which elements are used and how they will be nested in the hierarchy

DTDs can include element and attribute declarations, entities, notations, comments, and processing instructions

Here's an example of a DTD which is embedded in an XML document

<?XML version="1.0" standalone="yes"?>
<!DOCTYPE memo [
<!ELEMENT memo (header, memotext)>
<!ELEMENT header (to, cc, bcc*, from)>
<!ELEMENT to (name)>
<ATTLIST to
      type CDATA "To">
<!ELEMENT name (#PCDATA)>
<!ELEMENT cc (name)>
<ATTLIST cc
      type CDATA "CC">
<!ELEMENT bcc (name)>
<ATTLIST bcc
      type CDATA "BCC">
<!ELEMENT from (sender)>
<ATTLIST from
      type CDATA "From">
<!ELEMENT sender (#PCDATA)>
<!ELEMENT memotext (#PCDATA)>
<!ENTITY sig
"Yours in humor, Bozo">
]>

<-- This is the embedded DTD

<memo>
<header>
<to type="To">
<name>John Doe</name>
</to>
<cc type="CC">
<name>Jane Doe</name>
</cc>
<from type="From">
<sender>Bozo T. Clown</sender>
</from>
</header>
<!--This is the start of the memo text-->
<memotext>
Please take note our phone number has changed.&sig;
</memotext>
</memo>

Now let's take it apart

Home
DTD DTD 2 DTD 3 DTD 4 DTD 5 DTD 6 DTD 7 DTD 8 DTD 9
Next

DTD 10 DTD 11 DTD 12 DTD 13 DTD 14 DTD 15 DTD 16 DTD 17

Page by Howard Rosenbaum
Find me at hrosenba@indiana.edu You are here: http://www.slis.indiana.edu/hrosenba/www/Workshops/XML/Demo/dtd.html