Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Tagging the remainder of a body

From: George Cristian Bina <george@---------.--->
To: 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent