External DTDs

The DTDs I've created in this chapter so far have all been built into the documents that they are targeted for. However, you can also create and use external DTDs, where the actual DTD is stored in an external file (usually with the extension .dtd).

Using external DTDs makes it easy to create an XML application that can be shared by many people—in fact, that's the way many XML applications are supported. There are two ways to specify external DTDs—as private DTDs or as public DTDs. I'll take a look at private DTDs first.

Private DTDs are intended for use by people or groups privately—not for public distribution. You specify an external private DTD with the SYSTEM keyword in the <!DOCTYPE> element like this (notice also that because this document now depends on an external file, the DTD file order.dtd, I've changed the value of the standalone attribute from "yes" to "no"):

<?xml version = "1.0" standalone="no"?>
<!DOCTYPE DOCUMENT SYSTEM "order.dtd">
<DOCUMENT>
    <CUSTOMER>
        <NAME>
            <LAST_NAME>Smith</LAST_NAME>
            <FIRST_NAME>Sam</FIRST_NAME>
        </NAME>
        <DATE>October 15, 2001</DATE>
        <ORDERS>
            <ITEM>
                <PRODUCT>Tomatoes</PRODUCT>
                <NUMBER>8</NUMBER>
                <PRICE>$1.25</PRICE>
            </ITEM>
            <ITEM>
                <PRODUCT>Oranges</PRODUCT>
                <NUMBER>24</NUMBER>
                <PRICE>$4.98</PRICE>
            </ITEM>
            .
            .
            .
            <ITEM>
                <PRODUCT>Asparagus</PRODUCT>
                <NUMBER>12</NUMBER>
                <PRICE>$2.95</PRICE>
            </ITEM>
            <ITEM>
                <PRODUCT>Lettuce</PRODUCT>
                <NUMBER>6</NUMBER>
                <PRICE>$11.50</PRICE>
            </ITEM>
        </ORDERS>
    </CUSTOMER>
</DOCUMENT>

Here's the file order.dtd that holds the external DTD—note that it simply holds the part of the document that was originally between the [ and ] in the <!DOCTYPE> element:

<!ELEMENT DOCUMENT (CUSTOMER)*>
<!ELEMENT CUSTOMER (NAME,DATE,ORDERS)>
<!ELEMENT NAME (LAST_NAME,FIRST_NAME)>
<!ELEMENT LAST_NAME (#PCDATA)>
<!ELEMENT FIRST_NAME (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT ORDERS (ITEM)*>
<!ELEMENT ITEM (PRODUCT,NUMBER,PRICE)>
<!ELEMENT PRODUCT (#PCDATA)>
<!ELEMENT NUMBER (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
				

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.163.207