by Eric van der Vlist is published by O'Reilly & Associates (ISBN: 0596004214)
The final transformation I'll show here is much more widely used than you might think. Spreadsheets are familiar, very convenient to store, can manipulate large lists of information items, and have been used as a modeling tool for many years. The UBL OASIS Technical Committee (see http://www.oasis-open.org/committees/ubl/), which is in charge of a set of core components to be used by B2B applications and frameworks such as ebXML, has moved in this direction. Although this project uses a UML methodology, the release note of their 0.70 version states: "The current spreadsheet matrix used by UBL has proved the most versatile and manageable in developing a logical model of the UBL Library."
Recent spreadsheet software can work with XML formats, so generating RELAX NG schemas from such a tool is really easy.
Tip | |
---|---|
There is no standard way to represent XML documents in a spreadsheet. Thus the benefit of spreadsheets is their flexibility: you can define layouts specific to each application. |
Coming back to our library, we can formalize it in an OpenOffice spreadsheet as shown in Figure 14-7.
Figure 14-7 is basically nothing more than a catalog of each information item with just enough information to generate a schema. The benefit of using a spreadsheet is that it's easy to read and, when the catalog gets bigger, features such as filters, sort, and search become increasingly useful to help navigate over the catalog.
Generating RELAX NG schemas from the OpenOffice spreadsheet's XML format is really easy. The code for doing this is too long to cover here, but will be available at http://books.xmlschemata.org/relaxng/ and at this book's page on the O'Reilly web site http://www.oreilly.com/catalog/relax/. With that tool, it doesn't take much work to turn this spreadsheet into schemas such as:
<?xml version="1.0" encoding="utf-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <element name="library"> <a:documentation>Root element. Describes the whole library.</a:documentation> <zeroOrMore> <element name="book"> <a:documentation>Describes a book.</a:documentation> <attribute name="id"> <a:documentation>Identifier</a:documentation> <data type="token"/> </attribute> <attribute name="available"> <a:documentation>Is the book available?</a:documentation> <data type="boolean"/> </attribute> <element name="isbn"> <a:documentation>ISBN number</a:documentation> <data type="token"/> </element> <element name="title"> <a:documentation>Title of the book</a:documentation> <data type="token"/> <attribute name="xml:lang"> <a:documentation>Language</a:documentation> <data type="language"/> </attribute> </element> <zeroOrMore> <element name="author"> <a:documentation>Author of a book</a:documentation> <attribute name="id"> <a:documentation>Identifier</a:documentation> <data type="token"/> </attribute> <element name="name"> <a:documentation>Name</a:documentation> <data type="token"/> </element> <element name="born"> <a:documentation>Date of birth</a:documentation> <data type="date"/> </element> <element name="died"> <a:documentation>Date of death</a:documentation> <data type="date"/> </element> </element> </zeroOrMore> <zeroOrMore> <element name="character"> <a:documentation>Character of a book</a:documentation> <attribute name="id"> <a:documentation>Identifier</a:documentation> <data type="token"/> </attribute> <element name="name"> <a:documentation>Name</a:documentation> <data type="token"/> </element> <element name="born"> <a:documentation>Date of birth</a:documentation> <data type="date"/> </element> <element name="qualification"> <a:documentation>Qualification of a character</a:documentation> <data type="token"/> </element> </element> </zeroOrMore> </element> </zeroOrMore> </element> </start> </grammar> |
or, after a translation into the compact syntax by Trang:
namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0" start = ## Root element. Describes the whole library. element library { ## Describes a book. element book { ## Identifier attribute id { xsd:token }, ## Is the book available? attribute available { xsd:boolean }, ## ISBN number element isbn { xsd:token }, ## Title of the book element title { xsd:token, ## Language attribute xml:lang { xsd:language } }, ## Author of a book element author { ## Identifier attribute id { xsd:token }, ## Name element name { xsd:token }, ## Date of birth element born { xsd:date }, ## Date of death element died { xsd:date } }*, ## Character of a book element character { ## Identifier attribute id { xsd:token }, ## Name element name { xsd:token }, ## Date of birth element born { xsd:date }, ## Qualification of a character element qualification { xsd:token } }* }* } |
Here again, you can generate any style of schema; you're not limited to Russian dolls. It just depends on how you write the tool that converts from spreadsheet to schema.
This text is released under the Free Software Foundation GFDL.