[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

substitutionGroup across namespaces

From: Mark Proctor <mproctor@codehaus.org>
Date: Mon, 25 Oct 2004 10:44:20 +0200
Message-ID: <417CBCE4.2040009@codehaus.org>
To: xmlschema-dev@w3.org
substitutiongroup xs
In the http://drools.org project we have a base name space:
http://drools.org/rules
And three semantic namespaces:
http://drools.org/semantic/java
http://drools.org/semantic/groovy
http://drools.org/semantic/python

Each namespace xsd is in its own file.

A rule is made up of classes, conditions, consequences and at the moment 
in the rule.xsd we use the choice feature to allow a user to specify 
which one they want:
       <xs:choice>
         <xs:element ref="java:consequence"/>
         <xs:element ref="groovy:consequence"/>
         <xs:element ref="python:consequence"/>
       </xs:choice>
However this has the side affect of coupling the rule.xsd to the 
semantic xsds, and as a user only has the semantic xsds in the classpath 
that they wish to use they receive errors about the other namespaces, 
plus it makes it difficult for users wishing to add more semantic 
implementations as they need to alter rules.xsd.

To try and remove this coupling we wanted to use some sort of abstract 
class in rules.xsd to specify a type, which the semantics would then 
extend. It seems the only way to do this is with substitutionalGroup, 
however it refuses to work when the elements are in different files and 
namespaces.

I have included some sample code, any help would be greatly appreciated.

Regards

Mark

-------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
          targetNamespace="http://drools.org/rules"
          elementFormDefault="qualified"
          xmlns:rules="http://drools.org/rules">

 <xs:element name="rule-set">
   <xs:complexType>
     <xs:sequence>
       <xs:element minOccurs="0" maxOccurs="unbounded" ref="rules:rule"/>
     </xs:sequence>
     <xs:attribute name="name" use="required" type="xs:string"/>
     <xs:attribute name="description" type="xs:string"/>
   </xs:complexType>
 </xs:element>

 <xs:element name="rule">
   <xs:complexType>
     <xs:sequence>

       <xs:element name="parameter" maxOccurs="unbounded" >
         <xs:complexType>
           <xs:sequence>
             <xs:element ref="rules:class"/>
           </xs:sequence>
           <xs:attribute name="identifier" use="required" 
type="xs:string"/>
         </xs:complexType>
       </xs:element>

       <xs:element ref="rules:condition" maxOccurs="unbounded" />

       <xs:element ref="rules:consequence"/>

     </xs:sequence>
     <xs:attribute name="name" use="required" type="xs:string"/>
     <xs:attribute name="salience" type="xs:integer"/>
     <xs:attribute name="no-loop" type="xs:boolean"/>
     <xs:attribute name="description" type="xs:string"/>
   </xs:complexType>
   </xs:element>

 <xs:element name="class"       type="xs:string" abstract="true"/>
 <xs:element name="condition"   type="xs:string" abstract="true"/>
 <xs:element name="consequence" type="xs:string" abstract="true"/>

</xs:schema>
-------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 targetNamespace="http://drools.org/semantics/java"
 elementFormDefault="qualified"
 xmlns:java="http://drools.org/semantics/java"
 xmlns:rules="http://drools.org/rules">

 <xs:import namespace="http://drools.org/rules"/>

 <xs:element name="class"       type="xs:string" 
substitutionGroup="rules:class"/>
 <xs:element name="condition"   type="xs:string" 
substitutionGroup="rules:condition"/>
 <xs:element name="consequence" type="xs:string" 
substitutionGroup="rules:consequence"/>

</xs:schema>
Received on Monday, 25 October 2004 08:53:30 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.