- From: Eddie Robertsson <eddie@allette.com.au>
- Date: Mon, 12 Nov 2001 12:20:51 +1100
- To: Jeni Tennison <jeni@jenitennison.com>
- CC: Gary Robertson <gazinyork@hotmail.com>, xmlschema-dev@w3.org
> The identity constraints in XML Schema are clearly an 80/20 solution > to a hard problem. I don't think that adding full XPath support to > identity constraints will improve them *all* that much (although > definitely there are circumstances where it would help). Adding > Schematron-like rules to any complex type definition, on the other > hand... :) Since Schematron is built on top of XSLT, as soon as XPath support the PSVI this is exactly what we'll be able to do. And if we don't want to wait for the next XPath we can use Francis Norton's new "poor-man's PSVI...". What he's done is create an XSLT process that annotates an XML instance document with Normalized Unique Name (NUN) values as well as type information. For example say we have the following XML instance and XML Schema: XML instance: <root> <myString>hello world</myString> <root/> </root> XML Schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="rootType"> <xs:sequence minOccurs="0"> <xs:element name="myString" type="xs:string"/> <xs:element ref="root"/> </xs:sequence> </xs:complexType> <xs:element name="root" type="rootType"/> </xs:schema> Now if you run these two documents through Francis' process [1] you will get an annotated XML instance document that would look like this: <root elementNUN="#/element::root" typeNUN="#/type::rootType"> <myString elementNUN="#/type::rootType/element::myString" typeNUN="#/type::rootType/element::myString/type::*">hello world</myString> <root elementNUN="#/type::rootType/element::root" typeNUN="#/type::rootType"></root> </root> Since we now have an annotated XML instance document we can use this information to apply a Schematron rule to a complex type instead of an element. For example we can add a Schematron rule to the above schema like this: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="rootType"> <xs:annotation> <xs:appinfo> <pattern xmlns="http://www.ascc.net/xml/schematron" name="rootType constraints"> <rule context="*[@typeNUN="#/type::rootType"]"> <assert test="the test we want for all rootTypes"></assert> </rule> </pattern> </xs:appinfo> </xs:annotation> <xs:sequence minOccurs="0"> <xs:element name="myString" type="xs:string"/> <xs:element ref="root"/> </xs:sequence> </xs:complexType> <xs:element name="root" type="rootType"/> </xs:schema> So, in this case the Schematron rule will apply for all elements that have the type rootType disregarding the actual name of the element. This is indeed very powerful but of course the problem is that it now takes a number of XSLT processing steps in order to validate your document. However, with the next version of XPath this should be simpler to do. On a related issue, I think Francis' work be used as a starting point for the "simplified PSVI" that has been discussed on this list in the last month. > But then in many ways I think it's right that there should be a gap > between validation of the structure of an XML document and validation > of the relationships between values held within an XML document. > Mixing the modular style of XML Schema with XPath is pretty nasty > (although perhaps XPath 2.0 will help, if it supports testing of > user-defined types). I think it will but I'm not entirely sure. Cheers, /Eddie [1] http://www.geocrawler.com/archives/3/6317/2001/10/0/6840660/
Received on Sunday, 11 November 2001 20:13:48 UTC