A schema that uses attribute values to enforce content structure rules?

Greetings,


I am trying to express the semantics of our content model in an XML  
schema. I have a type whose allowed content is function of the values  
of an attribute. Here's a simplified "sketch" of the problem:

An element <A> has a required attribute "type", if A@type=="xml" then  
<A> may contain any (other namespace) XML:

     <A type="xml">
         <foo:B />
         <bar:C />
     </A>

If A@type=="Container" then <A> may any number of other <A> elements:

     <A type="Container">
	<A type="xml">
             <foo:B />
         </A>
	<A type="Container">
	    <A type="xml">
                 <bar:C />
             </A>
         </A>
     </A>

If A@type=="values" then <A> must contain one or more <value> elements:

     <A type="values">
         <value>1234</value>
     </A>



This pair of complexType and attributeGroup definitions:

     <xs:complexType name="A_Type">
         <xs:choice>
             <xs:sequence>
                 <xs:element name="value" type="xs:string"  
minOccurs="1" maxOccurs="unbounded"/>
             </xs:sequence>
             <xs:sequence>
                 <xs:element name="Attribute" type="A_Type"  
minOccurs="0"
                     maxOccurs="unbounded"/>
                 <xs:element ref="Alias" minOccurs="0"  
maxOccurs="unbounded"/>
             </xs:sequence>
             <xs:sequence>
                 <xs:any namespace="##other" minOccurs="0"  
maxOccurs="unbounded"
                     processContents="strict"/>
             </xs:sequence>
         </xs:choice>
         <xs:attributeGroup ref="A_attributes_Group"/>
     </xs:complexType>

     <xs:attributeGroup name="A_attributes_Group">
         <xs:attribute name="name" type="xs:string" use="required"/>
         <xs:attribute name="type" use="required">
             <xs:simpleType>
                 <xs:restriction base="xs:string">
                     <xs:enumeration value="values"/>
                     <xs:enumeration value="xml"/>
                     <xs:enumeration value="Container"/>
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
     </xs:attributeGroup>

Captures the structural requirements, but fails to enforce the  
relationship between the value of A@type and correct associated  
content of <A>

I can make a complexType for each of these cases, but I don't see how  
to combine them into a single type definition that enforces the 3  
content/structure rules based on the value of the A@type attribute.

Is it possible to enforce this kind of semantic/structural dependancy  
using a schema?

Is there an example of something like this that someone could point me  
to?


Thanks in advance!


Nathan




============================================================
Nathan Potter                 Oregon State University, COAS
ndp at coas.oregonstate.edu   104 Ocean. Admin. Bldg.
541 737 2293 voice            Corvallis, OR   97331-5503
541 737 2064 fax

Received on Sunday, 18 January 2009 15:10:04 UTC