Digital humanities


Maintained by: David J. Birnbaum (djbpitt@gmail.com) [Creative Commons BY-NC-SA 3.0 Unported License] Last modified: 2020-02-13T15:55:12+0000


Relax NG test answer key

The task

Your task is to create a Relax NG schema for our XML version of Edgar Allan Poe’s Annabel Lee. Your schema should constrain the XML while also allowing for the reasonable integration of new material. Hint: you will want to use repeatable or-groups when you model mixed content, and you can read about those under Mixed content in our Relax NG content models posting. Make sure that you validate the XML file with your schema before you are done.

Should you have any questions about the test, please post them in our obdurodon/dh_course issues area (and when you respond to someone’s query, which you are encouraged to do, you can nudge them in the right direction, but don’t give away the answer). You may use any reference material you would like while creating your schema (books, Internet, etc.), except that you cannot receive help from another person, and your work needs to be your own. When you are finished, upload your schema to CourseWeb, where we have created an assignment for it (you do not need to upload the XML).

Solution

There are multiple ways to model this document type effectively in Relax NG, so your solution need not have matched ours exactly. Among other things, Relax NG schemas are typically written to model not just a single document, but a document type—in this case, perhaps this poem and others that may be similar to it. For that reason, you will want to construct a schema that is not overly permissive, but also one that is not overly restrictive. Below is one solution:

start = poem
poem = element poem { title, poet, stanza+ }
title = element title { text }
poet = element poet { text }
stanza = element stanza { n, line+ }
n = attribute n { xsd:int }
line =
    element line {
        mixed { (person | place)* }
    }
person = element person { name, descriptor?, text }
name = attribute name { text }
descriptor = attribute descriptor { text }
place = element place { loc, text }
loc = attribute loc { text }

We regarded the xsd:int datatype for the @n attribute as extra credit, since Relax NG datatypes are a topic we mentioned only in passing. This datatype requires the value to be an integer, making it more restrictive (in a useful way) than just text would be. You can read about Relax NG datatypes in the datatype reference appendix of Eric van der Vlist’s Relax NG.