The objects of this assignment are:
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.
A <catalog>
consists of a
<company>
element followed by one
or more <department>
elements.
A <company>
element contains plain text.
A <department>
contains one or more
<item>
elements. It must have a
name
attribute and a unique code
attribute.
An <item>
element contains, in this order, a
<name>
, a <price>
, an
optional <manufacturer>
, a
color specification (see below), a
<summary>
, and
an optional <description>
The <name>
,
<manufacturer>
,
<summary>
, and
<description>
all contain plain text.
The <price>
is an empty element which has
a required amt
attribute that specifies the
price; it is plain text. It also has an optional
units
attribute, which may have a value of either
USD
or CDN
.
A color specification is either a single
<color>
element
(for those items that come in only one color),
a <color-list>
(for items that come in multiple colors),
or an <sku>
element
(for items that have no color). These
are further defined as:
A <color>
element contains
text, and has a required sku
attribute
and an optional hex
attribute.
The <color-list>
element contains one or more <color>
elements.
An <sku>
element contains text.
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:
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.
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.)
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.
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.
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.
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.