- From: George Cristian Bina <george@oxygenxml.com>
- Date: Tue, 14 Feb 2006 11:35:09 +0200
- To: Pete Cordell <petexmldev@tech-know-ware.com>
- Cc: "Paul B. Monday" <Paul.Monday@Sun.COM>, xmlschema-dev@w3.org
Pete Cordell wrote: [...] > If neither of these are OK, then from what I've heard on this list, > you'll need something like Schematron to impose the constraints (I'm > afraid I haven't had the chance to get round to using it myself.) Here it is a working example of XML Schema with embedded Schematron rules to check that the type value matches the message element. <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:sch="http://www.ascc.net/xml/schematron"> <xs:element name="test"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" ref="message"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="message"> <xs:annotation> <xs:appinfo> <sch:pattern name="Check that the type matches the element."> <sch:rule context="message[event]"> <sch:assert test="type='Event'">The type for event should be 'Event'.</sch:assert> </sch:rule> <sch:rule context="message[contact-information]"> <sch:assert test="type='Contact'">The type for contact-information should be 'Contact'.</sch:assert> </sch:rule> </sch:pattern> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:sequence> <xs:element ref="type"/> <xs:choice> <xs:element ref="contact-information"/> <xs:element ref="event"/> </xs:choice> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="type" type="xs:NCName"/> <xs:element name="contact-information"> <xs:complexType> <xs:sequence> <xs:element ref="address"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="address"> <xs:complexType/> </xs:element> <xs:element name="event"> <xs:complexType> <xs:sequence> <xs:element ref="stuff"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="stuff"> <xs:complexType/> </xs:element> </xs:schema> On a sample document like <?xml version="1.0"?> <test> <message> <type>Event2</type> <event> <stuff/> </event> </message> <message> <type>Contact2</type> <contact-information> <address/> </contact-information> </message> </test> It will give: SystemID: C:\george\workspace\oXygen\samples\test.xml Location: 3:0 Description: The type for event should be 'Event'. (type='Event') SystemID: C:\george\workspace\oXygen\samples\test.xml Location: 10:0 Description: The type for contact-information should be 'Contact'. (type='Contact') Best Regards, George --------------------------------------------------------------------- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com
Received on Tuesday, 14 February 2006 09:33:19 UTC