CIT041X Index > Assignment Relax NG Compact

Assignment Relax NG Compact
Creating and Using a Relax NG Compact File

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

Specification of the Language

This XML language describes ski reports.

HTML Subset

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:

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="">
<xh:p>Our rates are as follows <xh:em>on weekends

    <xh:td>Ski Lift</xh:td><xh:td align="right">$50.00</xh:td>

Please use namespaces to implement this subset of XHTML, as in the example above. The namespace URI for XHTML is

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.


Work in Stages

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:

    start = element ski-report
        element date {text},
        element entry {text} +

You could then test that definition against this sample file:

    <entry>First test</entry>
    <entry>Second test</entry>

Once you got that working, you could expand the definition of <entry> and modify your test file to match it.

Use definitions

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.

Worry about namespaces last

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:

  1. Do everything except the content of the <info> element, and just make it a placeholder until you learn about namespaces.
  2. Leave off the 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.
  3. Read about namespaces in the book and in the lecture notes and see if you can figure it out on your own.

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 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.

Checking Your Work

Use the jingvalidate.bat file on Windows, or 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