van der Vlist, Eric. “XML instances to validate XML schemas.” Presented at International Symposium on Quality Assurance and Quality Control in XML, Montréal, Canada, August 6, 2012. In Proceedings of the International Symposium on Quality Assurance and Quality Control
in XML. Balisage Series on Markup Technologies, vol. 9 (2012). https://doi.org/10.4242/BalisageVol9.Vlist02.
International Symposium on Quality Assurance and Quality Control in XML August 6, 2012
Balisage Paper: XML instances to validate XML schemas
Eric van der Vlist
Dyomedea
Eric is an independent consultant and trainer. His domain of expertise include Web
development and
XML technologies.
He is the creator and main editor of XMLfr.org, the
main site dedicated to XML technologies in French, the author of the O'Reilly animal
books XML
Schema and RELAX NG and a member or the ISO DSDL (http://dsdl.org) working group focused on XML schema languages.
He is based in Paris and you can reach him by mail (vdv@dyomedea.com) or meet him in one of the many conferences where he presents his
projects.
Published under the Creative Commons "cc by" license
Abstract
Ever modified an XML schema? Ever broken something while fixing a bug or adding a
new feature? As with
any piece of engineering, the more complex a schema is, the harder it is to maintain.
In other domains,
unit tests dramatically reduce the number of regressions and thus provide a kind of
safety net for
maintainers. Can we learn from these techniques and adapt them to XML schema languages?
In this workshop
session, we develop a schema using unit test techniques, to illustrate their benefits
in this
domain.
The workshop is run as an exchange between a customer (played by Tommie Usdin) and
a schema expert (played by
Eric van der Vlist).
The customer, who needed a schema for her to-do list XML application, is puzzled by
the "test first programming"
technique imposed by the schema expert.
At the end of the day (or workshop), will she be converted to this well-known agile
or extreme programming
technique adapted to the development of XML schemas?
Step 1: Getting started
Hi Eric, can you help me to write a schema?
— Customer
Hi Tommie, yes, sure, what will the schema be about?
— Expert
I need a vocabulary for my to-do lists, with to-do item...
— Customer
OK, you've told me enough, let's get started.
— Expert (interrupting his customer)
Get started? but I haven't told you anything about it!
— Customer
Right, but it's never too soon to write tests when you do test first programming!
— Expert
Note
In test first programming (also called test driven development),
developers create test case (usually unit test cases) before implementing a function.
The test suite is
run, code is written based on the result of these tests and the test suite and code
are updated until
all the tests pass.
The vocabulary used to define these test cases has been inspired by the SUT (XML Schema Unit Test) project. It's a simple
vocabulary (composed of only three different elements) allowing to pack several XML
instances together
with the outcome validation result. It uses conventions that you'll discover during
the course of this
workshop.
That's true, but you don't have to write a schema to write XML documents.
— Expert
I know, but you're here to write a schema! Furthermore, right now we accept anything.
I don't want
to have XML documents with anything as a root element!
— Customer
That's a good reason to write a schema, but before that we need to add a test in our
suite
first.
Now that we've updated the test suite, we run it again.
— Expert
You see? We do already support list title elements!
— Expert
Sure, but I don't want to accept any content in my to-do list. And the title element
should be
mandatory. And it should not be empty but have at least one character!
This is the first example with non-top-level tf:case elements. To understand how this
works, we must look in more detail to the algorithm used by the framework to split
a test suite into
instances. The algorithm consists in two steps:
Loop over each tf:case element
Suppression of the tf:case elements and of the top level elements which are
not ancestors of the current tf:case element.
This description may look complex, but the result is a rather intuitive way to define
sub-trees that are common to several test cases.
Now that we've updated the test suite, we run it again.
split-tests.xsl is the XSLT transformation that splits a test suite into top level
element test cases. This transformation has no dependence on Orbeon Forms and can
be manually
run against a test suite.
run-test.xpl is the XPL pipeline that runs a test case.
list-suites.xpl is the XPL pipeline that gives the list available test cases.
view.xhtml is the XForms application that displays the results.
Copy the orbeon-resources/ directory under /WEB-INF/resources/apps/ in your
orbeon webapp directory
Or, alternatively, copy the tefisc/ directory wherever you want, edit web.xml.sav to replace
<param-value>/home/vdv/projects/tefisc/orbeon-resources</param-value>
by the location of this directory on your filesystem, replace /WEB-INF/web.xml by
this file and restart your application server.