Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Nathan Potter <ndp@----.-----------.--->
To: xmlschema-dev@--.---
Date: 1/15/2009 10:48:00 AM

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




From mike@s... Sun Jan 18 15:34:27 2009
Received: from maggie.w3.org ([193.51.208.68])
	by frink.w3.org with esmtp (Exim 4.63)
	(envelope-fro


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