Creating Document Type Declarations

You define the syntax and structure of elements using a document type definition (DTD), and you declare that definition in a document using a document type declaration. We've seen that you use the <!DOCTYPE> element to create a document type declaration. This element can take many different forms, as you see here (here, URL is the URL of a DTD, and rootname is the name of the root element); we'll see all these forms in this chapter:

  • <!DOCTYPE rootname [ DTD ]>

  • <!DOCTYPE rootname SYSTEM URL>

  • <!DOCTYPE rootname SYSTEM URL [DTD]>

  • <!DOCTYPE rootname PUBLIC identifier URL>

  • <!DOCTYPE rootname PUBLIC identifier URL [DTD]>

To use a DTD, you need a document type declaration, which means that you need a <!DOCTYPE> element. The <!DOCTYPE> element is part of a document's prolog. Here's how I add a document type declaration to the document ch02_01.xml that we developed in the previous chapter:

 <?xml version = "1.0" standalone="yes"?>  <!DOCTYPE DOCUMENT [   .   .   .   ]>  <DOCUMENT>     <CUSTOMER>         <NAME>             <LAST_NAME>Smith</LAST_NAME>             <FIRST_NAME>Sam</FIRST_NAME>         </NAME>         <DATE>October 15, 2003</DATE>         <ORDERS>             <ITEM>                 <PRODUCT>Tomatoes</PRODUCT>                 <NUMBER>8</NUMBER>                 <PRICE>.25</PRICE>             </ITEM>             .             .             .             <ITEM>                 <PRODUCT>Asparagus</PRODUCT>                 <NUMBER>12</NUMBER>                 <PRICE>.95</PRICE>             </ITEM>             <ITEM>                 <PRODUCT>Lettuce</PRODUCT>                 <NUMBER>6</NUMBER>                 <PRICE>.50</PRICE>             </ITEM>         </ORDERS>     </CUSTOMER> </DOCUMENT> 

Now it's up to us to supply the actual DTD that is part of this <!DOCTYPE> element.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net