Assertions is a new facility in XML Schema 1.1 language. It's officially described here, in the W3C spec, http://www.w3.org/TR/xmlschema11-1/#cAssertions. For an explanation of assertions feature and to know number of practical examples, please read the article [2] in "References" section below.

This page describes implementation details of XML Schema 1.1 assertions feature, in Xerces-J XML Schema processor.

Status of assertions development: The assertions implementation in Xerces-J is complete, and Xerces team has checked in the code for this, at the SVN repository (https://svn.apache.org/repos/asf/xerces/java/branches/xml-schema-1.1-dev/). The only assertions feature which still needs to be implemented and tested is, the id attribute on xs:assert and xs:assertion instructions. The work for this is underway.
The user feedback would be helpful at this point.

Assertions usage in Complex Types (as defined in the XML Schema 1.1 spec)

Assertions usage in Simple Types (as defined in the XML Schema 1.1 spec)

<simpleType

</simpleType>

<restriction

</restriction>

Design approach

The Xerces XSModel (an object model representing an XML Schema) is modified to handle assertions, for the XML Schema 1.1 "simple" and "complex" types.

Since 'assertion' is now a new facet for XML Schema simple types, the current facet data structures, and the facet traverser are enhanced to support XML Schema 1.1 assertions.

To implement assertions for complex types, the complex type traverser of Xerces is modified.

Assertions XPath 2.0 processing implementation

Xerces provides a Java interface API, for integrating Xerces with XPath 2.0 evaluation engines. It should be possible to plug in any compliant XPath 2.0 engine to the Xerces assertions processor, by writing a small Java layer complying to this interface.

Xerces provides a sample implementation of this interface for Eclipse XPath2/PsychoPath XPath 2.0 engine. This should be very good enough, for open source Xerces-J product.

We have tried our best, to write an efficient implementation of XPath 2.0 integration for assertions. For nested elements having assertions, the child/descendant elements share the XPath (XDM) tree with the top most element. For each distinct XDM tree involved in assertions processing, we keep a reference of it's root node, and discard these references when assertions evaluation is complete for that tree.

A caution for Schema authors: If we are specifying assertions for the root element of the XML document, a tree will be built for assertions processing, which could be as large as the XML document. Where memory is a concern for large XML documents, assertions may be specified at an inner level [1] of the XML documents, as far as possible. This [1] will cause smaller assertion trees to be built, thereby reducing memory footprint of the XML application. It is also worth knowing, that assertions trees are generally smaller than corresponding generic XML infoset trees, because assertions trees only contain element and attribute information, along with certain XML Schema type annotations, whereas generic XML trees contain other information like processing instructions, comments and so on.

Run-time notes

  1. By default, the Xerces-J Schema processor would select the Eclipse/PsychoPath engine for XPath 2.0 processing. Xerces-J has a provision for the user, to select between different XPath 2.0 engines for evaluating assertions. This can be done by setting the Java system property, org.apache.xerces.assertProcessor. Xerces-J has an out of the box support for PsychoPath XPath 2.0 engine. If the user doesn't set this property, or set it's value to, org.apache.xerces.impl.xs.XMLAssertPsychopathImpl, the PsychoPath processor would be selected for XPath 2.0 processing.

  2. If user's wish to use an XPath 2.0 engine other than PsychoPath, for working with Xerces-J assertions, they need to write a custom Java layer similar to org.apache.xerces.impl.xs.XMLAssertPsychopathImpl, and integrate it with the other XPath 2.0 engine, using the XPath 2.0 engine's public APIs. Xerces-J would publish an API, to integrate to any available standard compliant XPath 2.0 engines.

  3. Xerces-J flags error messages during assertions processing, as recommended by the XML Schema 1.1 specification. If the user provides a syntactically wrong XPath 2.0 expression, the Schema processing terminates, flagging an error message to the user with key, cvc-xpath.3.13.4.2. If the XPath 2.0 syntax is correct, but any of the assertions evaluate to "false", the Schema processing terminates, and an error message is shown to the user with key, cvc-assertion.3.13.4.1.

References:

  1. An introduction to XML Schema 1.1, An overview of the key improvements over XML Schema 1.0 and an in-depth look at datatypes

  2. An introduction to XML Schema 1.1, Co-occurence constraints using XPath 2.0


Mukul Gandhi

XML_Schema_1.1_Assertions (last edited 2009-09-20 23:16:14 by localhost)