| Previous | Next
Two DTD ExamplesSome of the best techniques for DTD design only become apparent when you look at larger documents. In this section, we'll develop DTDs that cover the two different document formats for describing people that were presented in Example 2-4 and Example 2-5 of the last chapter. Data-Oriented DTDsData- oriented DTDs are very straightforward. They make heavy use of sequences, occasional use of choices, and almost no use of mixed content. Example 3-6 shows such a DTD. Since this is a small example, and since it's easier to understand when both the document and the DTD are on the same page, we've made this an internal DTD included in the document. However, it would be easy to take it out and put it in a separate file. Example 3-6. A flexible yet data-oriented DTD describing people<?xml version="1.0"?> <!DOCTYPE person [ <!ELEMENT person (name+, profession*)> <!ELEMENT name EMPTY> <!ATTLIST name first CDATA #REQUIRED last CDATA #REQUIRED> <!-- The first and last attributes are required to be present but they may be empty. For example, <name first="Cher" last=""> --> <!ELEMENT profession EMPTY> <!ATTLIST profession value CDATA #REQUIRED> ]> <person> <name first="Alan" last="Turing"/> <profession value="computer scientist"/> <profession value="mathematician"/> <profession value="cryptographer"/> </person> The DTD here is contained completely inside the internal DTD subset. First a person This declaration also requires that all Both Narrative-Oriented DTDsNarrative-oriented DTDs tend be a lot looser and make much heavier use of mixed content than do DTDs that describe more database-like documents. Consequently, they tend to be written from the bottom up, starting with the smallest elements and building up to the largest. They also tend to use parameter entities to group together similar content specifications and attribute lists. Example 3-7 is a standalone DTD for biographies like the one shown in Example 2-5 of the last chapter. Notice that not everything it declares is actually present in Example 2-5. That's often the case with narrative documents. For instance, not all web pages contain unordered lists, but the XHTML DTD still needs to declare the Example 3-7. A narrative-oriented DTD for biographies<!ATTLIST biography xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink"> <!ELEMENT person (first_name, last_name)> <!-- Birth and death dates are given in the form yyyy/mm/dd --> <!ATTLIST person born CDATA #IMPLIED died CDATA #IMPLIED> <!ELEMENT date (month, day, year)> <!ELEMENT month (#PCDATA)> <!ELEMENT day (#PCDATA)> <!ELEMENT year (#PCDATA)> <!-- xlink:href must contain a URI.--> <!ATTLIST emphasize xlink:type (simple) #IMPLIED xlink:href CDATA #IMPLIED> <!ELEMENT profession (#PCDATA)> <!ELEMENT footnote (#PCDATA)> <!-- The source is given according to the Chicago Manual of Style citation conventions --> <!ATTLIST footnote source CDATA #REQUIRED> <!ELEMENT first_name (#PCDATA)> <!ELEMENT last_name (#PCDATA)> <!ELEMENT image EMPTY> <!ATTLIST image source CDATA #REQUIRED width NMTOKEN #REQUIRED height NMTOKEN #REQUIRED ALT CDATA #IMPLIED > <!ENTITY % top_level "( #PCDATA | image | paragraph | definition | person | profession | emphasize | last_name | first_name | footnote | date )*"> <!ELEMENT paragraph %top_level; > <!ELEMENT definition %top_level; > <!ELEMENT emphasize %top_level; > <!ELEMENT biography %top_level; > The root |