XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: [xml-dev] Is Schematron (using XPath 2.0) functionally a superset of XML Schemas?

> Since one of the major goals and benefits of Schematron 
> is good diagnostics, reducing a content model to a regular 
> expression doesn't seem a particularly smart idea.

The example below shows Schematron expressing data requirements in a
much more elegant and natural fashion than XML Schemas.

EXAMPLE

Here is a simple XML document:

<?xml version="1.0" encoding="UTF-8"?>
<latitude>74.231455</latitude>

DATA REQUIREMENTS

Here are the data requirements on the value of the <latitude> element:

1. The value must be a decimal value.
2. The value must be between -90 and +90.
3. There must be six digits to the right of the decimal point.

ANALYSIS OF IMPLEMENTATIONS

Below I show how the above data requirements are implemented using XML
Schemas.  Then I show how they are implemented using Schematron.

ANALYSIS OF THE XML SCHEMA IMPLEMENTATION

If you examine the XML Schema implementation you will see that it
expresses this: "The latitude is a string.  And the string is
constrained by the given regular expression."   However, the above data
requirements clearly says that the latitude value is a decimal value,
not a string value.  This results in great confusion.  Accrediting the
XML Schema implementation against the data requirements will be very
difficult as the peculiarities of XML Schemas must be translated into
the data requirements. 

The requirement that the value must be between -90 and +90 is hidden
within a very complex regular expression. Ditto for the requirement
that there must be six digits to the right of the decimal point.
Again, accreditation will be a nightmare.

Conclusion: The capabilities of XML Schema provide a poor way of
expressing the above data requirements. 

ANALYSIS OF THE SCHEMATRON IMPLEMENTATION

Schematron has an assertion that addresses each of the three data
requirements.  

The first assertion expresses the first data requirement in a clear and
natural fashion: 

    ". castable as xs:decimal"

The second assertion expresses the second data requirement in a clear
and natural fashion: 

    "(xs:decimal(.) ge -90.0) and (xs:decimal(.) le +90.0)"

And the third assertion expresses the third data requirement in a clear
and natural fashion: 

    "matches(., '^[0-9]*\.[0-9]{6}$')"

In addition, each assertion identifies the data requirement that it is
implementing, using the see="..." attribute).  This is very important
for accrediting a schema against its data requirements.

Lastly, each assertion has an associated human-readable diagnostic.

CONCLUSION

For this example, Schematron is superior to XML Schemas in these
respects:
- expressibility
- accreditabiliy
- human-readable error messages


EXPRESSING THE DATA REQUIREMENTS USING XML SCHEMA

The above data requirements can be expressed by XML Schemas as follows:

<element name="latitude">
    <simpleType>
        <restriction base="string">
            <pattern
value="[0-9]\.[0-9]{6}|[1-8][0-9]\.[0-9]{6}|90\.[0-9]{6}|-[0-9]\.[0-9]{
6}|-[1-8][0-9]\.[0-9]{6}|-90\.[0-9]{6}"/>
        </restriction>
    </simpleType>
</element>


EXPRESSING THE DATA REQUIREMENTS USING SCHEMATRON

   <sch:pattern id="Latitude_Validation">

      <sch:rule context="latitude">

         <sch:assert test=". castable as xs:decimal"
                     diagnostics="Decimal"
                     see="Data Requirement #1">
             The latitude must be a decimal value.
         </sch:assert>

         <sch:assert test="(xs:decimal(.) ge -90.0) and (xs:decimal(.)
le +90.0)"
                     diagnostics="Range"
                     see="Data Requirement #2">
             The latitude must be between -90 and +90.
         </sch:assert>

         <sch:assert test="matches(., '^[0-9]*\.[0-9]{6}$')"
                     diagnostics="Precision"
                     see="Data Requirement #3">
             The latitude must have six digits to the right of the
decimal point.
         </sch:assert>

      </sch:rule>

   </sch:pattern>

   <sch:diagnostics> 

      <sch:diagnostic id="Decimal">

         Your latitude value has an improper datatype.  
         Data requirement #1 says that the latitude must
         be a decimal value.

      </sch:diagnostic>

      <sch:diagnostic id="Range">

         Your latitude value has an improper value.  
         Data requirement #2 says that the latitude must
         be between -90 and +90.

      </sch:diagnostic>

      <sch:diagnostic id="Precision">

         Your latitude value does not have the correct precision.  
         Data requirement #3 says that the latitude must
         have six digits to the right of the decimal point.

      </sch:diagnostic>

   </sch:diagnostics>


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS