W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2009

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

From: Nathan Potter <ndp@coas.oregonstate.edu>
Date: Thu, 15 Jan 2009 18:48:00 -0800
Message-Id: <0B167DEC-6D4E-4969-BA9C-D3E1821A1846@coas.oregonstate.edu>
To: xmlschema-dev@w3.org
Cc: Nathan Potter <ndp@coas.oregonstate.edu>


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 />

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

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

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

     <A type="values">

This pair of complexType and attributeGroup definitions:

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

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

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  

Thanks in advance!


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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:50 UTC