February 14, 2002 - Figuring Out the XML Grammar | WebReference

February 14, 2002 - Figuring Out the XML Grammar

Yehuda Shiran February 14, 2002
Writing A DTD for An XML File
Tips: February 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

The DTD file contains several types of declarations. First, it includes declarations about the XML document structure. You need to specify each element's content. The root element sales, see below for a listing of our mydvd XML file, includes the elements summary and data:

  <!ELEMENT sales (summary, data)>
Be sure to put all child elements within parentheses and separated by commas. The summary element includes the following elements: heading, subhead, description, author, and date:

  <!ELEMENT summary (heading, subhead, description, author, date)>
The data element includes one or more elements of month. You specify a repetition with an asterisk:

  <!ELEMENT data (month*)>
The month element consists of two elements: name and week (one or more instances):

  <!ELEMENT month (name, week*)>
Here is the mydvd XML file:

  <?xml version="1.0"?>
  <?xml-stylesheet type="text/xsl" href="mydvd7.xsl"?>
  <!DOCTYPE sales SYSTEM "mydvd8.dtd">
    <sales>
      <summary>
        <heading>MyDVD Rental Store</heading>
        <subhead>Periodical Sales Report</subhead>
        <description>Sales Report for January, February, and &lt;&month;&gt; of 2001</description>
        <author>author: &preparedby;</author>
  	    <date>Jan 30, 2002</date>
      </summary>
      <data>
        <month>
          <name>January 2001</name>
          <week number="1" dvds_rented="12000" />
          <week number="2" dvds_rented="15000" />
          <week number="3" dvds_rented="18000" />
          <week number="4" dvds_rented="11800" />		  
        </month>
        <month>
          <name>February 2001</name>
          <week number="2" dvds_rented="12390" />
          <week number="3" dvds_rented="19050" />
          <week number="4" dvds_rented="11200" />		  
        </month>
        <month>
          <name>March 2001</name>
          <week number="1" dvds_rented="15300" />
          <week number="2" dvds_rented="12390" />
          <week number="3" dvds_rented="10050" />
          <week number="4" dvds_rented="11230" />		  
        </month>
      </data>
    </sales>