Document Type Definition (DTD)

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

Java APIs for XML Kick Start
By Aoyon Chowdhury, Parag Choudhary

Table of Contents
Appendix B.  XML: A Quick Tour


A DTD defines the way that an XML document should be created. It is essentially a constraint mechanism for an XML document. It defines the elements, the order in which they can occur, the attributes elements can have, the possible values the elements can have, and so on. The reason we need to have a DTD is to ensure that the applications that share the XML documents have a common understanding of what the tags mean. This also helps the XML parsing application process and search within the XML file. Essentially, the DTD provides the XML its portability. It ensures that any application that has the XML document, and its corresponding DTD, can process the document in a correct and consistent manner. And as you saw earlier, a DTD is also the place where you declare the internal entities.

In the CarParts.xml file, you saw an internal DTD subset that declared the entities used in the XML file. In e-business scenarios, a standards organization often publishes a DTD that describes how the XML document should be modeled so as to permit participating businesses to have a common understanding of the semantics, thus facilitating exchange of data. An external DTD is a text file with the special syntax defined for creating DTDs. A possible external DTD for the CarParts.xml file is shown in bold in Listing B.2. We will use code snippets from this DTD to explain how to create a DTD.

Listing B.2 The DTD for the CarParts.xml File
<?xml version='1.0'?> <!--  XML file that describes car parts --> <!DOCTYPE carparts[ <!ENTITY  companyname "Heaven Car Parts (TM)"> <!ENTITY  companyweb "http://carpartsheaven.com"> <!ELEMENT carparts (hubcaps,supplier,engines, carbodies,wheels,carstereos,forCDATA)> <!ELEMENT engines (engine+)> <!ELEMENT carbodies (carbody+)> <!ELEMENT wheels (wheel+)> <!ELEMENT carstereos (carstereo+)> <!ELEMENT forCDATA ANY> <!ELEMENT hubcaps (#PCDATA)> <!ELEMENT supplier (#PCDATA)> <!ATTLIST supplier             name CDATA #REQUIRED       URL CDATA #REQUIRED > <!ELEMENT engine (#PCDATA)*> <!ATTLIST engine             id ID #REQUIRED             type CDATA #REQUIRED             capacity (1000 | 2000 | 2500 ) #REQUIRED             price CDATA #IMPLIED             text CDATA #IMPLIED > <!ELEMENT carbody (#PCDATA)*> <!ATTLIST carbody             id CDATA #REQUIRED             type CDATA #REQUIRED             color CDATA #REQUIRED > <!ELEMENT wheel (#PCDATA)*> <!ATTLIST wheel             id CDATA #REQUIRED             type CDATA #REQUIRED             price CDATA #IMPLIED         size  (X | Y | Z) #IMPLIED > <!ELEMENT carstereo (#PCDATA)*> <!ATTLIST carstereo             id CDATA #REQUIRED             manufacturer CDATA #REQUIRED             model CDATA #REQUIRED             Price CDATA #REQUIRED > ]> <carparts> ....... </carparts> 

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
Top

[0672324342/app02lev1sec12]

 
 


JavaT APIs for XML Kick Start
JAX: Java APIs for XML Kick Start
ISBN: 0672324342
EAN: 2147483647
Year: 2002
Pages: 133

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