spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column103


Web Services, Part VIII: Reading DTDs with JavaScript

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Assembling and Calling DTDs

You can validate an XML file with a document type definition (DTD). DTDs use a formal grammar to describe the structure and syntax of compliant XML documents; they specify content and values allowed for the XML document. You define the DTD of your XML file in its DOCTYPE declaration. The DOCTYPE declaration can either point to an inline DTD or can be a reference to an external DTD file.

Our mydvd XML file can be validated against the following DTD:

<!ELEMENT sales (summary, data)>
<!ELEMENT summary (heading, subhead, description, author)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT subhead (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT data (month*)>
<!ELEMENT month (name, week*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT week (#PCDATA)>
<!ATTLIST week number CDATA #REQUIRED>
<!ATTLIST week dvds_rented CDATA #REQUIRED>
<!ENTITY preparedby "John Smith">
<!ENTITY month "April">

Here is our mydvd XML file:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="mydvd7.xsl"?>
<!DOCTYPE sales SYSTEM "mydvd7.dtd">
  <sales>
    <summary>
      <heading>MyDVD Rental Store</heading>
      <subhead>Periodical Sales Report</subhead>
      <description>Sales Report for January, February,
        and March of 2001</description>
      <author>author: John Smith</author>
    </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="1" dvds_rented="11500" />
        <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>

Notice how we call the DTD in our XML file above:

<!DOCTYPE sales SYSTEM "mydvd7.dtd">

The DOCTYPE's syntax is as follows:

<!DOCTYPE Name SYSTEM FileName [InternalDeclarations]>

where:


Next: How to define an XML file structure

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 11, 2002
Revised: February 11, 2002

URL: http://www.webreference.com/js/column103/2.html