XML
  Home arrow XML arrow Page 5 - The Fundamentals of DTD Design
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

The Fundamentals of DTD Design
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2001-09-27

    Table of Contents:
  • The Fundamentals of DTD Design
  • DTD Who?
  • Rainy Days
  • Simply Elementary
  • What's The Frequency, Bobby?
  • Turning Up The Heat
  • An Entity In The Attic
  • The Old Popcorn Trick

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    The Fundamentals of DTD Design - What's The Frequency, Bobby?
    (Page 5 of 8 )

    A number of special symbols can be added to an element declaration in order to define its frequency and order, or the frequency and order of its child elements. Here's a quick list:

    symbol description --------------------------------------------------------- + one or more occurrence(s) * zero or more occurrence(s) ? zero or one occurrence(s) | choice
    If you're familiar with regular expressions, you'll feel right at home with these symbols - they're almost identical to the symbols used to build regular expression patterns.

    Let's take this for a quick spin. Consider the following revised XML document

    <?xml version="1.0"?> <!DOCTYPE weather SYSTEM "weather.dtd"> <weather> <city>New York</city> <high>26</high> <low>18</low> <forecast>rain</forecast> <city>Boston</city> <forecast>snow</forecast> <city>London</city> <high>32</high> <forecast>sun</forecast> </weather>
    and then take a look at its associated DTD

    <!ELEMENT weather (city, high*, low*, forecast)+> <!ELEMENT city (#PCDATA)> <!ELEMENT forecast (#PCDATA)> <!ELEMENT high (#PCDATA)> <!ELEMENT low (#PCDATA)>
    How did I come up with this? It's simple - you just have to take it step by step.

    The first thing to do is allow for more than one "city" block within the "weather" element.

    <!ELEMENT weather (city, high, low, forecast)+>
    Next, the "high" and "low" elements must be made optional.

    <!ELEMENT weather (city, high*, low*, forecast)+>
    And Bob's your uncle!

    The | operator sets up a list of alternatives, and comes in handy when an element must contain any one of a finite list of alternatives. Consider the following XML document,

    <?xml version="1.0"?> <addressbook> <record> <name>John Smith</name> <street>24, Main Street</street> <city>Poodle Springs</city> <zip>16628</zip> <country>USA</country> <tel> <home>947 3838</home> </tel> </record> <record> <name>Sherlock Holmes</name> <tel> <home>827 3483</home> </tel> <fax> <home>364 2929</home> </fax> <email> <home>holmes@greatdetectives.org</home> </email> </record> <record> <name>Jane Doe</name> <email> <work>jane@somedomain.com</work> </email> </record> </addressbook>
    and take a look at the corresponding DTD, specifically at the declarations for the "tel", "fax" and "email" elements, which may contain either "home" or "work" nested child elements.

    <!ELEMENT addressbook (record+)> <!ELEMENT record (name, street?, city?, zip?, country?, tel?, fax?, email?)> <!ELEMENT name (#PCDATA)> <!ELEMENT street (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT country (#PCDATA)> <!ELEMENT zip (#PCDATA)> <!ELEMENT tel (home | work)> <!ELEMENT fax (home | work)> <!ELEMENT email (home | work)> <!ELEMENT home (#PCDATA)> <!ELEMENT work (#PCDATA)>
    The | operator also comes in handy when defining elements which are of so-called "mixed" type - they can contain either data or other elements. Here's an example:

    <?xml version="1.0"?> <surrealism> The elongated <color>blue</color> <animal>fox</animal> jumped over the <color>green</color> <vegetable>pumpkin</vegetable> and morphed into <personality>Richard VIII</personality> </surrealism>
    Pay close attention to the "surrealism" element, which can contain either character data or any one of the listed elements:

    <!ELEMENT animal (#PCDATA)> <!ELEMENT color (#PCDATA)> <!ELEMENT personality (#PCDATA)> <!ELEMENT surrealism (#PCDATA | animal | color | personality | vegetable)*> <!ELEMENT vegetable (#PCDATA)>
    Obviously, all these symbols can also be combined to create weird and wonderful rules for the document to follow. An example awaits you at the end of the article...but first, attributes.

    More XML Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    XML ARTICLES

    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway