IBM®
Skip to main content
    United States [change]      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     
     
  XML on TPF: A Short Tutorial IBM

XML on TPF: A Short Tutorial — Page 3 of 14
Create a Sample DTD

A Document Type Definition (DTD) is one method of defining the acceptable tags for an XML document. A DTD has a strict syntax and can be either inside the XML document itself or in a separate file. When it is in a separate file, the XML document has specific coding to reference the location of the DTD. This sample DTD resides in its own file.

This sample DTD might be used to represent a passenger name record (PNR) in the airline industry. The organization of data in an XML document is the key to its success. However, this DTD is less focused on a realistic implementation and more focused on demonstrating the various ways to write XML data:

  • Elements:
                    <!ELEMENT FirstName (#PCDATA)>
                    
  • Nested Elements:
                    <!ELEMENT FormOfPayment (ccIssuer, ccNumber, ccExpiration)>
                            <!ELEMENT ccIssuer (#PCDATA)>
                            <!ELEMENT ccNumber (#PCDATA)>
                            <!ELEMENT ccExpiration (#PCDATA)>
                    
  • Attributes:
                    <!ELEMENT cityPair EMPTY>
                            <!ATTLIST cityPair
                                    departLoc CDATA #REQUIRED
                                    arriveLoc CDATA #REQUIRED
                            >
                    

Before continuing, do the following:
  1. Open the sample DTD in another browser window.
  2. See how elements, nested elements, and attributes are used.
  3. Click File --> Save As.
  4. Save the file in C:\xmltut as pnrdtd. The default file name may be pnrdtd.txt or pnrdtd.html. If this is true, ensure that you remove the .txt or .html extension. (The XML document on the next page calls the DTD, so the name must match exactly. For this, there is no extension to the DTD file.)
  5. Close the window by clicking the X in the upper-right corner.
Note: When you are using a DTD on your TPF 4.1 system, you will need to include a declaration statement at the top of the document to indicate in which encoding the DTD is written. For example:
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
When this line is included, some browsers will attempt to parse the DTD as an XML document. We have omitted this line from the sample DTD to ensure that you can view the DTD in your browser. See the TPF XML User's Guide for more information about encodings.

Once you have saved the DTD, you are ready to continue.

For More Information
See the TPF XML User's Guide for the following:

  • A list of books and Web sites for learning about DTDs and their syntax
  • More information about specifying the encoding of your documents on the TPF 4.1 system.

PreviousNext

Back to the Beginning
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14

 

Close This Window.

 

    About IBM Privacy Contact