Sharing DTDs
Home ] Up ] Operators & Keywords ] [ Sharing DTDs ] Declaring Attributes ]

 

 

Clearly, it would be useful to specify the DTD for an XML document externally from the document itself.  You can do this by specifying the following in the DOCTYPE definition. For example:

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE memo SYSTEM "memoDTD.dtd">
<memo>
  <from>College President</from>
  <to>
    <name>Faculty</name>
  </to>
  <to>
    <name>Students</name>
  </to>
  <to>
    <department>Computer Science</department>
  </to>
  <body>
  Here is a very important message for all members of the
  College community. Blah, blah, blah...
  </body>
  <priority><high></high></priority>
</memo>

Where the memoDTD.dtd file contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT memo (from, to+, body, priority?)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT to (name | department)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT department (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT priority (high | medium | low)>
<!ELEMENT high EMPTY>
<!ELEMENT medium EMPTY>
<!ELEMENT low EMPTY>

Again, if you want to see how your browser renders the above XML document, click here.

 
The page was last updated February 19, 2008