XML
  Home arrow XML arrow Page 6 - 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

    Dell PowerEdge Servers

    The Fundamentals of DTD Design - Turning Up The Heat
    (Page 6 of 8 )

    Just as you can declare elements, a DTD also allows you to define the attributes attached to each element. An attribute declaration typically looks like this:

    <!ATTLIST elementName attributeName contentType modifier>
    In order to demonstrate, consider the following XML document, which adds a couple of attributes to the previously declared XML elements.

    <?xml version="1.0"?> <weather> <city state="NY">New York</city> <temperature> <high units="celsius">23</high> <low units="celsius">10</low> </temperature> <forecast>sun</forecast> </weather>
    Here's the corresponding DTD:

    <!-- element declarations --> <!ELEMENT weather (city, temperature, forecast)> <!ELEMENT city (#PCDATA)> <!ELEMENT forecast (#PCDATA)> <!ELEMENT high (#PCDATA)> <!ELEMENT low (#PCDATA)> <!ELEMENT temperature (high, low)> <!-- attribute declarations --> <!ATTLIST city state CDATA #REQUIRED> <!ATTLIST high units CDATA #REQUIRED> <!ATTLIST low units CDATA #REQUIRED>
    Let's examine the first one a little more closely:

    <!ATTLIST city state CDATA #REQUIRED>
    In English, this declares that the element "city" has an attribute named "state" containing character data. The additional #REQUIRED modifier indicates that this is a required attribute - failure to include it will render the XML document invalid.

    A number of different content types are available for attributes. You're already familiar with character data - here's a quick list of the others:

    type description ------------------------------------------ CDATA character data ID unique identifier IDREF reference to unique identifier of another element IDREFS list of identifiers NMTOKEN string literal or token NMTOKENS list of tokens ENTITY entity ENTITIES list of entities
    You can also specify a list of allowed attribute values by enclosing them in parentheses and separating them with the | operator. The following attribute declaration does just that, limiting the list of allowed values for the "units" attribute to either "celsius" or "fahrenheit".

    <!ATTLIST high units (celsius | fahrenheit) #REQUIRED>
    A number of modifiers are available, each applying a special characteristic to the attribute. For example, you can specify a default value for the attribute by enclosing it in quotes; this default value is used if the attribute is absent.

    <!ATTLIST high units (celsius | fahrenheit) "fahrenheit">
    The #IMPLIED modifier is used to declare a particular attribute as optional.

    <!ATTLIST high units #IMPLIED>
    And finally, the #FIXED keyword is used to fix an attribute value to something specific, allowing the XML document author no choice in the matter.

    <!ATTLIST high units (celsius | fahrenheit) #FIXED "fahrenheit">
    If an element has more than one attribute, you can declare them all within the same attribute declaration. Consider the following XML document,

    <?xml version="1.0"?> <movie id="42" genre="sci-fi"> <title>Star Wars</title> <cast>Mark Hamill, Carrie Fisher, Harrison Ford</cast> <director>George Lucas</director> </movie>
    and its associated DTD, which demonstrates how this works.

    <!-- element declarations --> <!ELEMENT movie (title, cast, director)> <!ELEMENT title (#PCDATA)> <!ELEMENT cast (#PCDATA)> <!ELEMENT director (#PCDATA)> <!-- attribute declarations --> <!ATTLIST movie id CDATA #REQUIRED genre CDATA #REQUIRED
    Let's move on to entities.

    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 3 hosted by Hostway