Thursday, June 1, 2017

XPath 2.0 atomization in XML Schema 1.1 validation

XPath 2.0 atomization as a concept, as applicable to XML Schema 1.1 validation is worth looking at. I would like to ponder on this in this post, with a brief example.

Consider the following brief XML Schema 1.1 validation example.

XSD 1.1 document:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
   <xs:element name="X">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="a" type="xs:integer"/>
            <xs:element name="b" type="xs:integer"/>
         </xs:sequence>
         <xs:assert test="a gt b"/>
      </xs:complexType>
   </xs:element>
 
</xs:schema>

XML document that is fed to the XML Schema 1.1 validator, when validating with the above XSD document:

<?xml version="1.0"?>
<X>
  <a>4</a>
  <b>7</b>
</X>

This XML document fails validation, because "a" is less than "b". Now what is XPath 2.0 atomization, as for in this example that I want to talk about?

Since the XML document has been validated with the mentioned XSD, while building the XPath tree to apply <assert>, the nodes of the tree are annotated (or decorated) with the XSD types as mentioned in the XSD document. Therefore, the <assert> XPath 2.0 expression "a gt b", comes with runtime availability of the corresponding XSD types on <assert> tree nodes for "a" and "b". In XPath 2.0 terms, the <assert> tree nodes for "a" and "b" have been atomized. The Schema aware XPath 2.0 in action, is same in <assert> as in the generic Schema aware XPath 2.0 processor.

The XSD 1.1 processor that I've used for this example is located at https://svn.apache.org/repos/asf/xerces/java/branches/xml-schema-1.1-dev/.

1 comment:

Anton Udovychenko said...
This comment has been removed by the author.