Monday, August 7, 2017

Mathematical table data with XML Schema 1.1

Here's a simple example, using XML Schema 1.1 <assert> to validate elementary school mathematical tables.

XML document:
<?xml version="1.0"?>
<table id="2">

XSD 1.1 document:
<?xml version="1.0"?>
<xs:schema xmlns:xs="">
   <xs:element name="table">
           <xs:element name="x" minOccurs="10" maxOccurs="10"/>
        <xs:attribute name="id" type="xs:positiveInteger" use="required">
             <xs:documentation>Mathematical table of @id is represented.</xs:documentation>
        <xs:assert test="x[1] = @id"/>
        <xs:assert test="every $x in x[position() gt 1] satisfies $x = $x/preceding-sibling::x[1] + @id">
              <xs:documentation>An XPath 2.0 expression validating the depicted mathematical table.    

No comments: