CIT041X Index > Assignment: DTD

Creating and Using a Simple DTD

Hints for this assignment

Read Everything Before Doing Anything.

The objects of this assignment are:

Specification of the Language

The catalog example used in part two of Assignment 1 had no specification for its “grammar.” Here is an English-language description of that grammar, which you will turn into a DTD.

Note: there is no element named “color specification.” It’s just a shorthand for “<color> or <color-list> or <sku>.”

The reason that we have this strange setup for colors, color-lists, and SKUs is that every item in the catalog must have an SKU (Stock Keeping Unit, a sort of inventory code). Here are the cases that these elements cover:

  1. An item doesn't have a color (e.g., "Diet Soda 12-pack") In that case, it needs an <sku> element to keep track of inventory.

  2. An item comes in only one color (e.g., a whiteboard). It will have one <color> element, and that element has a required sku attribute to keep track of the inventory for that item. The hex attribute is optional, and is used only if its color happens to be representable as a color code like you find in HTML (#ffca03, etc.)

  3. An item comes in many colors (for example, ballpoint pens). You now need a <color-list> which has individual <color> elements. Each of them has a different sku attribute, so that we can keep track of how many blue pens we've sold vs. black pens vs. red pens. Each one also has an optional hex attribute in case its color happens to be representable as an HTML color code.

Using the DTD

The well-formed version of file catalog_wellformed.xml, is displayed on this web page. Save it with a name as described below. Using this as your base, add a <!DOCTYPE...> that references your DTD. Modify this new file to be valid with respect to the DTD.

Checking Your Work

Use the validate.bat file on Windows, or shell script on Unix/Linux. The validator will give no error messages if everything is OK.

Naming Your Files

Your files must be saved as plain ASCII text, but that does not mean that they must both end with the extension .txt. If your name is Joe Doakes, your DTD file must have a name like doakes_j_specs.dtd and the XML file must have a name like doakes_j_catalog.xml. This means that the XML file would start like this:

<?xml version="1.0"?>
<!DOCTYPE catalog SYSTEM "doakes_j_specs.dtd">

Please send both files to the instructor.