Read everything before doing anything.
The objects of this assignment are:
See instructor’s sample files
See a note about <interleave> if using the XML syntax
See a note about the &
operator if using the compact syntax
This XML language describes ski reports.
A <ski-report> consists of a
<date> element followed by one
or more <entry> elements.
A <date> element contains a date
in the form yyyy-mm-dd. For example,
March 15, 2003 would be 2003-03-15.
An <entry> contains a
<name> element,
<address> element, and a
<phone> element in that order, followed by
(in any order), a <base>,
and optional <lifts> element,
a set of <open> and <close>
elements, which must appear in that order, and an <info>
element.
Thus, the following order is OK:
<base> <info> <open> <close> <lifts>
but this one isn’t:
<lifts> <info> <close> <open> <base>
since <open> and <close> aren’t
in order any more.
The <name> element contains text, and
has a required id attribute, which must be unique.
The <address> element contains a
<street> or <box> element
(depending upon whether the address is a street address or a post office
box number). This is followed by the <city>,
<state>, and <zip> elements.
The <state> element must be in the form of two
capital letters. The <zip> element may be either a
five-digit or nine-digit zip code, as in 95129 or
95129-3427.
The <phone> element has the form
of nnn-nnn-nnnn; (example: 408-555-1212)
The <base> element is an empty element with
attributes:
units, which may have a value of either
in or cmmin, which must be a positive integermax, which must be a positive integerThe <lifts> element must be a positive
integer.
The <open> and <close>
elements both contain a time in the form hh:mm, where the
hour goes from 00 to 23 and the
minutes from 00 to 59.
Hint: Let's say you wanted to have a month of the year,
from 01 to 12. This pattern:
[01][0-9] wouldn’t work, because it allows
19 as a month. Instead, you need to break it up
into a pattern like this:
(0[1-9])|(1[0-2]).
The <info> contains
a small subset of HTML as described below.
First, we define inline elements as the
<em> and <strong> elements,
which may contain text and other inline elements. Given that
definition, the <info> element may contain
zero or more occurrences of:
Text with inline elements OR
The <p> (paragraph) element, which may
contain text with inline elements, OR
The <table> element, which is defined as
follows:
A <table> element contains
one or more <tr> elements.
Each <tr> element contains
one or more <td> or <th>
elements.
Each <td> or <th>
element may contain text
with inline elements and
<p> (paragraphs).
The <td> and <th>
elements each have an optional align attribute
with possible values of left,
right, or center (lowercase only).
You may have <table> elements
within an <td> or <th> if you wish.
This is not a requirement, but it sure makes the RNG file
easier to write, believe it or not.
Notice that this is a highly recursive definition. Here's an example of
a valid <info> element:
<info xmlns:xh="http://www.w3.org/1999/xhtml">
<xh:p>Our rates are as follows <xh:em>on weekends
<xh:strong>only</xh:strong></xh:em>.</xh:p>
<xh:table>
<xh:tr>
<xh:th>Item</xh:th><xh:th>Price</xh:th>
</xh:tr>
<xh:tr>
<xh:td>Ski Lift</xh:td><xh:td align="right">$50.00</xh:td>
</xh:tr>
</xh:table>
Please use namespaces to implement this subset of XHTML, as in the
example above. The namespace URI for XHTML is
http://www.w3.org/1999/xhtml.
You will also need to produce mixed content.
See
information about a problem you might encounter if using the
XML syntax and <interleave>, or the similar
information if using compact syntax.
Note: You will want to add some of this XHTML to your file to test that your RNG file handles it properly. I will test your RNG against one of my own sample files.
Don’t try to write the entire Relax NG file at once.
Instead, take a small but complete section and write it, and then
write a test file that tests only that portion. Example:
“A <ski-report> consists of a
<date> element followed by one
or more <entry> elements.” Without any
further detail, the Relax NG
might look something like this:
grammar
{
start = element ski-report
{
element date {text},
element entry {text} +
}
}
You could then test that definition against this sample file:
<ski-report>
<date>2003-02-25</date>
<entry>First test</entry>
<entry>Second test</entry>
</ski-report>Once you got that working, you could expand the definition of
<entry> and modify your test file to match it.
If you notice that two elements have exactly the same content
(as <open> and <close> do),
use a definition for that content, and avoid
duplication. If you are building your Relax NG file and you realize
that the <address> element’s content is too
difficult to handle all at once, just say
address-defn, and create a
placeholder:
address-defn =
element address { text }You can come back later and fill in the content of the definition.
If you haven’t gotten to the point of understanding
those weird-looking tags in the sample file
that look like <h:table>, don’t say,
“Well, I guess I can’t do any work at all until I
understand this stuff.” Instead, you may either:
<info> element, and just make it a placeholder
until you learn about namespaces.h: and html:
prefixes in your sample file, and treat the HTML subset as just
another set of tags in the ski report. Once you understand namespaces, you can
add the appropriate information to the Relax NG file and then put
back the prefixes in your sample file.
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 RNG compact file should have a name like
doakes_j_3.rnc and the XML file should have a name
like doakes_j_3.xml. Just send me the RNG file.
Use the jingvalidate.bat file on Windows, or
jingvalidate.sh shell script on Unix/Linux.
See more about jing. The
validator will give no error messages if everything is OK.
If you have named your files as shown above, you would type
this to validate the compact syntax on Windows:
jingvalidate -c doakes_j_3.rnc doakes_j_3.xml