Home arrow XML arrow Page 8 - The Fundamentals of DTD Design

The Old Popcorn Trick - XML

Ever tried to read a DTD, and failed miserably? Ever wondered what all those symbols and weird language constructs meant? Well, fear not - this crash course will get you up to speed with the basics of DTD design in a hurry.

  1. The Fundamentals of DTD Design
  2. DTD Who?
  3. Rainy Days
  4. Simply Elementary
  5. What's The Frequency, Bobby?
  6. Turning Up The Heat
  7. An Entity In The Attic
  8. The Old Popcorn Trick
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 6
September 27, 2001

print this article


And that just about covers everything I have to say on the topic. Before I go, though, I'd like to run through a composite example illustrating everything you've learned thus far.

Take a look at the following XML document

<?xml version="1.0"?> <!DOCTYPE review SYSTEM "movie.dtd"> <review id="42"> <header> <title>Pearl Harbor</title> <cast>Ben Affleck, Josh Hartnett and Kate Beckinsale</cast> <director>Michael Bay</director> <duration units="m">167</duration> <genre>Drama</genre> <slug>War Games</slug> <author>J. Doe</author> <date>2001-08-08</date> </header> <body> <para>On December 7, 1941, Japan unexpectedly attacked the American naval base at Pearl Harbor, hoping to gain the initiative in the war against Europe. As it turned out, the attack had the effect of galvanizing the <quote>sleeping American giant</quote>, resulting in the utter rout of the Japanese and German armies and bolstering America's dominant role in world politics. </para> <para>While <title>Pearl Harbor</title>'s love story may seem unbelievably trite, the effects are most certainly not. The Japanese attack on the naval port is described in tremendous detail, and is perhaps the most compelling reason to watch this film. With over forty minutes of reel time devoted to the attack, you've probably never seen anything like it before; it's a visual spectacle that hits home more than any written description ever will. Bay's direction is superb - he knows just where to put the camera, and he always gets the money shot - and the cinematography and visuals - especially those shot in the train station, with steam billowing out in the background - simply gorgeous. </para> <para>While I think the love story embedded within <title>Pearl Harbor</title> isn't really all that compelling - <title>Moulin Rouge</title> did it better - this is still a film worth watching, if only to understand a little bit of history! </para> </body> </review>
and then see if you can put together a DTD for it. Here's my version:

<!-- element declarations --> <!ELEMENT review (header,body) > <!ELEMENT header (title,cast,director,duration,genre,slug,author,date) > <!ELEMENT title (#PCDATA) > <!ELEMENT cast (#PCDATA) > <!ELEMENT director (#PCDATA) > <!ELEMENT duration (#PCDATA) > <!ELEMENT genre (#PCDATA) > <!ELEMENT slug (#PCDATA) > <!ELEMENT author (#PCDATA) > <!ELEMENT date (#PCDATA) > <!ELEMENT body (para+) > <!ELEMENT para (#PCDATA|quote|title)* > <!ELEMENT quote (#PCDATA) > <!-- attribute declarations --> <!ATTLIST review id CDATA #REQUIRED > <!ATTLIST duration units (m | h) "m" >
And that's about it from me. In case you're interested in finding out about the more arcane aspects of DTDs - notations, parameter entities and overrides - you should consider checking out the following links.

The W3C's XML specification, at http://www.w3.org/TR/2000/REC-xml-20001006

The DocBook DTD, a specification for technical manuals and material, at http://www.oasis-open.org/docbook/xml/4.1.2/index.shtml

An interesting article on DTD construction, at http://www.xml.com/pub/a/2000/06/xmleurope/schemas.html

If, on the other hand, all you were looking for was a working knowledge of DTDs to get you though your day, I hope you found it here. I'll be back soon with another article on a related technology, XML Schema, which is quickly gaining followers on account of its ease of use and powerful data-validation capabilities (think of it as DTDs on steroids, but without the nasty symbols). Until then, though...be good!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- 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...

Developer Shed Affiliates


Dev Shed Tutorial Topics: