DTD Comments

As you can see, DTDs can become fairly complex, especially in longer and more involved documents. To make things easier for the DTD author, the XML specification allows you to place comments inside DTDs.

DTD comments are just like normal XML commentsin fact, they are normal XML comments, and they're often stripped out by the XML processor. (The W3C allows XML processors to remove comments, but some processors pass comments on to the underlying application.) Here's an example in which I have added comments to ch02_01.xml:

Listing ch03_07.xml
 <?xml version = "1.0" standalone="yes"?>  <!DOCTYPE DOCUMENT [   <!-- DOCUMENT is the root element -->   <!ELEMENT DOCUMENT (CUSTOMER)*>   <!-- CUSTOMER stores customer data -->   <!ELEMENT CUSTOMER (NAME,DATE,ORDERS)>   <!-- NAME stores the customer name-->   <!ELEMENT NAME (LAST_NAME,FIRST_NAME)>   <!-- LAST_NAME stores customer's last name -->   <!ELEMENT LAST_NAME (#PCDATA)>   <!-- FIRST_NAME stores customer's last name -->   <!ELEMENT FIRST_NAME (#PCDATA)>   <!-- DATE stores order data -->   <!ELEMENT DATE (#PCDATA)>   <!-- ORDERS stores customer orders -->   <!ELEMENT ORDERS (ITEM)*>   <!-- ITEM represents a customer purchase -->   <!ELEMENT ITEM (PRODUCT,NUMBER,PRICE)>   <!-- PRODUCT represents a purchased product -->   <!ELEMENT PRODUCT (#PCDATA)>   <!-- NUMBER indicates the number of item purchased -->   <!ELEMENT NUMBER (#PCDATA)>   <!-- PRICE is the item's price -->   <!ELEMENT PRICE (#PCDATA)>   ]>  <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>Oranges</PRODUCT>                 <NUMBER>24</NUMBER>                 <PRICE>.98</PRICE>             </ITEM>         </ORDERS>     </CUSTOMER>     <CUSTOMER>         <NAME>             <LAST_NAME>Jones</LAST_NAME>             <FIRST_NAME>Polly</FIRST_NAME>         </NAME>         <DATE>October 20, 2003</DATE>         <ORDERS>             <ITEM>                 <PRODUCT>Bread</PRODUCT>                 <NUMBER>12</NUMBER>                 <PRICE>.95</PRICE>             </ITEM>             <ITEM>                 <PRODUCT>Apples</PRODUCT>                 <NUMBER>6</NUMBER>                 <PRICE>.50</PRICE>             </ITEM>         </ORDERS>     </CUSTOMER>     <CUSTOMER>         <NAME>             <LAST_NAME>Weber</LAST_NAME>             <FIRST_NAME>Bill</FIRST_NAME>         </NAME>         <DATE>October 25, 2003</DATE>         <ORDERS>             <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> 


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