Building a DTD

The next step in XML design is to build a DTD based on the rough instance we worked out for the previous example. A DTD, in its simplest form, contains a declaration of every element you want to use in your XML instances. Examining the XML instance we defined in the previous section, the elements are

  • E-MAIL

  • FROM

  • TO

  • SUBJECT

  • BODY

Each of these elements must be defined within the DTD using an “ELEMENT” keyword, such as:

<!ELEMENT E-MAIL (FROM, TO, SUBJECT, BODY)>
<!ELEMENT FROM (#CDATA)*>
<!ELEMENT TO (#CDATA)*>
<!ELEMENT SUBJECT (#CDATA)*>
<!ELEMENT BODY (#CDATA)*>

Each of the preceding lines declares an element that legally can be part of our XML instances. Each declaration has two parts: the element name, such as FROM, and its

Get XML and SQL: Developing Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.