CIS 97YT Index > Assignment 2

Assignment 2
Creating and Using a Simple DTD

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 should turn into a DTD.

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 (which stands for Stock Keeping Unit, and is an 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 ex1b.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 validate.sh shell script on Unix/Linux. The validator will give no error messages if everything is OK.

Naming Your Files

Your files should 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 should have a name like doakes_j_2.dtd and the XML file should have a name like doakes_j_2.xml. This means that the XML file would start like this:

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

Please send both files to the instructor.