Altova Mailing List Archives>Archive Index >xmlschema-dev Archive Home >Recent entries >Thread Prev - Re: Tagging the remainder of a body [Thread Next] Re: Tagging the remainder of a bodyTo: Pete Cordell <petexmldev@--------------.---> Date: 2/14/2006 1:35:00 PM 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 www.---.com From ht@i... Tue Feb 14 09:38:25 2006 Received: from maggie.w3.org ([193.51.208.68]) by frink.w3.org with esmtp (Exim 4.50) id 1F8w | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
