This Version: V 0.6 (29 January 2003)
Latest Version: http://examplotron.org/
This namespace: http://examplotron.org/0/
Previous Version: V 0.5 (20 January 2003)
Examplotron 0.x is a proof of concept including this page, compile.xsl (a XSLT transformation that transforms examplotron documents into Relax NG schemas that validate "similar" documents) and a set of examples.
The description of the namespace version convention I intend to use for examplotron has been posted for discussion on xml-dev.
Note that this release (0.5) is a transitional release between previous releases based on XSLT validation with their own semantic and future releases which will be based on DSDL validation involving Relax NG and Schematron. Examplotron 0.5 is a rewrite of Examplotron 0.4 keeping the same set of features (with a couple of exceptions) under the new architecture to evaluate the changes implied by the move. Future releases will build on this base to resume adding new features.
Editor:
The purpose of examplotron is to use instance documents as a lightweight schema language-- eventually adding the information needed to guide a validator in the sample documents.
"Classical" XML validation languages such as DTDs, W3C XML Schema, Relax, Trex or Schematron rely on a modeling of either the structure (and eventually the datatypes) that a document must follow to be considered as valid or on the rules that needs to be checked.
This modeling relies on specific XML serialization syntaxes that need to be understood before one can validate a document and is very different from the instance documents and the creation of a new XML vocabulary involves both creating a new syntax and mastering a syntax for the schema.
Many tools (including popular XML editors) are able to generate various flavors of XML schemas from instance documents, but these schemas do not find enough information in the documents to be directly useable leaving the need for human tweaking and the need to fully understand the schema language.
Examplotron may then be used either as a validation language by itself, or to improve the generation of schemas expressed using other XML schema languages by providing more information to the schema translators.
The obvious limitation of working with sample documents is that while this is very efficient to describe patterns that can be "shown" in a document, this cannot by itself be used to describe abstract "constructed" patterns.
To workaround this limitation, one need to introduce modeling elements or attributes, moving to an hybrid schema language involving both pure "schema by example" and modeling or rules construction.
The current release includes such an attribute (eg:occurs) to provide a control on the number of occurrences of an element (see section "Occurrences" for a detailed description of this attribute).
I plan to consider the addition of other similar elements or attributes to workaround other similar restrictions such as:
This first instance document (examplotron1.xml) is also a examplotron schema:
<?xml version="1.0" encoding="UTF-8"?> <foo> <bar>My first examplotron.</bar> <bar>Hello world</bar> </foo>
This schema will validate all the documents without any namespace and the "same" structure, i.e. three element nodes (a document element of type "foo" with exactly two children elements of type "bar") and no attributes.
The examplotron compiler (i.e. the compile.xsl XSLT sheet) transforms the examplotron schema into a Relax NG schema (examplotron1.rng) that can be applied to any document to check if it has the same structure.
The structure of examplotron1.rng (and therefore the transformation defined in compile.xsl) is very straightforward:
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="foo"> <element name="bar"> <text/> </element> <element name="bar"> <text/> </element> </element> </start> </grammar>
Attributes are also supported as shown by examplotron2.xml:
<?xml version="1.0" encoding="UTF-8"?> <foo> <bar true="no longer">My first examplotron.</bar> <bar>Hello world</bar> </foo>
Which will include the definition of the "true" attribute (examplotron2.rng):
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="foo"> <element name="bar"> <attribute name="true"/> <text/> </element> <element name="bar"> <text/> </element> </element> </start> </grammar>
Note that, unlike in preceding versions, including consecutive elements with the same name generates consecutive definitions of these elements with different content models.
Controlling the number of the occurrences by adding as many elements as needed is rapidly verbose and do not cope with optional or arbitrary big number of occurrences. For these two cases, examplotron defines a simple mechanism inspired by the DTDs allowing to override the definition of the occurrences (examplotron3.xml):
<?xml version="1.0" encoding="UTF-8"?> <foo xmlns:eg="http://examplotron.org/0/"> <bar eg:occurs="+">Hello world</bar> <!-- eg:occurs could also have been set to "*", "." or "?" --> </foo>
The value of the eg:occurs attributes can be "*" (0 or more), "+" (1 or more), "." (exactly one) or "?" (0 or 1) and defined the number of occurrences of the element (examplotron3.rng):
<?xml version="1.0" encoding="utf-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="foo"> <oneOrMore> <element name="bar"> <text/> </element> </oneOrMore> </element> </start> </grammar>
Examplotron does support namespaces without any known restriction using namespaces in the examplotron documents as in any instance document (examplotron4.xml):
<?xml version="1.0" encoding="UTF-8"?> <foo xmlns:eg="http://examplotron.org/0/" xmlns:bar="http://http://examplotron.org/otherns/"> <bar:bar eg:occurs="+">Hello world</bar:bar> <!-- eg:occurs could also have been set to "*", "." or "?" --> </foo>
is straightforwardly translated into (examplotron4.rng):
<?xml version="1.0" encoding="utf-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start> <element name="foo"> <oneOrMore> <element name="bar" ns="http://http://examplotron.org/otherns/"> <text/> </element> </oneOrMore> </element> </start> </grammar>
In order to describe more complex rules, it is possible to define assertions (i.e. statements that need to be met) as XPath expressions using "eg:assert" attributes (examplotron5.xml):
<?xml version="1.0" encoding="UTF-8"?> <foo xmlns:eg="http://examplotron.org/0/" eg:assert="sum(percent)=100"> <!-- The sum of the values of the "percent" element needs to be equal to 100 --> <percent eg:occurs="+">100</percent> </foo>
The implementation of this feature is optional and may may vary depending on the architecture of the implementation. One of the possibilities is to generate Schematron embedded assertions as supported by Sun's MSV (examplotron5.rng):
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:sch="http://www.ascc.net/xml/schematron"> <start> <element name="foo"> <sch:assert test="sum(percent)=100"/> <oneOrMore> <element name="percent"> <text/> </element> </oneOrMore> </element> </start> </grammar>
Assertions can be used without restriction on document using namespaces, but please remember that XPath expressions do not support default namespaces (examplotron6.xml):
<?xml version="1.0" encoding="UTF-8"?> <foo:foo xmlns:eg="http://examplotron.org/0/" eg:assert="sum(bar:percent)=100" xmlns:foo="http://examplotron/otherns/foo" xmlns:bar="http://examplotron/otherns/bar"> <bar:percent eg:occurs="+">100</bar:percent> </foo:foo>
To deal with possible redefinitions of namespace prefixes, the compiler copies all the namespaces nodes found in the element where the assertion is found in the template (examplotron6.rng):
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:sch="http://www.ascc.net/xml/schematron"> <start> <element name="foo" ns="http://examplotron/otherns/foo"> <sch:assert xmlns:eg="http://examplotron.org/0/" xmlns:foo="http://examplotron/otherns/foo" xmlns:bar="http://examplotron/otherns/bar" test="sum(bar:percent)=100"/> <oneOrMore> <element name="percent" ns="http://examplotron/otherns/bar"> <text/> </element> </oneOrMore> </element> </start> </grammar>
Many thanks to David Carlisle for this tip.
To be (re) defined to match either one or both "include" and "externalRef" patterns from Relax NG.
These should not be needed any longer.
This mailing list is for discussing issues, bugs, questions and future development of Examplotron.
To subscribe, send a mail to examplotron-request@xmlschemata.org with "subscribe" in the subject or body.
This CVS repository gives you access on the detailed history of the documents composing the Examplotron distribution.
This database gives you access to bug and feature requests reports posted for Examplotron. Feel free to use it to post your own reports.
This documentation has been written as a RDDL document and this section will be developed to include more resources related to examplotron.
This compiler is a XSLT transformation that compiles an examplotron schema into a XSLT transformation that can be used to validate documents that are conform to this schema.
The compiler must be run using an EXSLT compliant XSLT processor. The resulting schema must use a Relax NG processor (with support for embedded Schematron rules to support eg:assert).
This W3C XML Schema (Proposed Recommendation, 16 March 2001) schema describes the examplotron vocabulary and can be imported in W3C XML Schema to validate examplotron schemas.
A CSS stylesheet borrowed from RDDL used to provide the "look-and-feel" of this document, suitable in general for RDDL documents.
Original version of the previous CSS stylesheet on rddl.org.
The chapter 7. of the XYZFind Server User's Guide described a schema language used by XYZFind Server that is very similar to examplotron (no longer available online).
This early proposal for XSL proposed a syntax similar to the one used by examplotron for expressing patterns.
Home page of the Relax NG Oasis TC.
I have been pleasantly surprised after a couple of hours working on examplotron that this simple tool was beginning to be useful while still very simple (or simplistic).
The current version is already a powerful tool that can be used to validate documents.
It can be used as a main validation tool, or as a complement of a more classical validation tool, for instance, to add additional requirements and constraints to existing vocabularies when an application is using a subset of a vocabulary.
This being said, the simplicity of the tools is leaving room for many applications and extensions on which your feedback is welcome:
Many thanks to the many people that have given me hints, ideas or encouragements or even let me think that examplotron could be the best invention since the French baguette.
Note: the French baguette is another very simple invention made only of flour, salt, yeast and water (exactly like examplotron that is made out of XML 1.0, Namespaces in XML 1.0, XPath 1.0 and XSLT 1.0). The Englo-American sliced bread (often used in this context), involving more ingredients and postprocessing is far more complex and does obviously not belong to the same category than examplotron.
Non normative list (by chronological order): Simon St.Laurent, Edd Dumbill, John Cowan, Len Bullard, Rick Jelliffe, Evan Lenz, Dan Brickley, Jonathan Borden, David Mundie, David Carlisle, Murata Makoto, Cyril Jandia, Amelia A. Lewis, Gavin Thomas Nicol, Tim Mueller-Seydlitz, Michael Champion, Wendell Piez...
Major architectural change with constant set of features.
Bug fixes
Copyright (c) 2001-2003 Eric van der Vlist
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ERIC VAN DER VLIST BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.