W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2004

Constraining structure elements in a certain context to be isomorphic

From: Helka Folch <hfolch@free.fr>
Date: Wed, 09 Jun 2004 16:42:29 +0200
Message-ID: <40C721D5.7040009@free.fr>
To: xmlschema-dev@w3.org
Is it possible with XSD schemas or RELAX-NG to constrain the occurrences 
of elements in a certain context to be isomorphic with respect to 
structure: to have the same sub-elements and attributes in that context 
(among the subelements and attributes allowed by their content model) ?

In particular, I would like to able to constrain the child elements  of 
an element to all have the same sub elements and attributes as each 
other. (I would like the branches of an element to be isomporphic,as 
long as the isomorphism respects the content model)

For instance, in the following schema I would like to constrain the 
child elements ('b') of 'a' to be isomorphic :


<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">


  <xs:element name="a">
    <xs:complexType>
      <xs:sequence>
	<xs:element ref="b" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
  </xs:element>

 <xs:element name="b">
   <xs:complexType>
    <xs:choice>
     <xs:element ref="c" minOccurs="1" maxOccurs="unbounded" />
     <xs:element ref="d" minOccurs="1" maxOccurs="unbounded" />
    </xs:choice>
  </xs:complexType>
 </xs:element>


<xs:element name="c">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="xs:string">
	  <xs:attribute name="c_attr1" type="xs:ID"/>
        <xs:attribute name="c_attr2" type="xs:ID"/>
    </xs:extension>
   </xs:simpleContent>
   </xs:complexType>
 </xs:element>


<xs:element name="d">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="xs:string">
	  <xs:attribute name="d_attr1" type="xs:ID"/>
        <xs:attribute name="d_attr2" type="xs:ID"/>
    </xs:extension>
   </xs:simpleContent>
   </xs:complexType>
 </xs:element>




I would like the following 2 instance documents to be valid :


<?xml version="1.0" encoding="iso-8859-1"?>
<a  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="test.xsd">
  <b>
    <c c_attr1="ezrz">sdfgdfg</c>
  </b>
  <b>
    <c c_attr1="gfhf">sdfgdfg</c>
  </b>
</a>





<?xml version="1.0" encoding="iso-8859-1"?>
<a  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="test.xsd">
  <b>
    <d d_attr2="ezrz">sdfgdfg</d>
  </b>
  <b>
    <d d_attr2="gfhf">sdfgdfg</d>
  </b>
</a>


And the following 2 instance documents to be invalid (because structure of 'b' sin't isomorphic)


<?xml version="1.0" encoding="iso-8859-1"?>
<a  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="test.xsd">
  <b>
    <d d_attr2="ezrz">sdfgdfg</d>
  </b>
  <b>
    <c c_attr2="gfhf">sdfgdfg</c>
  </b>
</a>



<?xml version="1.0" encoding="iso-8859-1"?>
<a  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="test.xsd">
  <b>
    <c c_attr1="ezrz">sdfgdfg</c>
  </b>
  <b>
    <c c_attr2="gfhf">sdfgdfg</c>
  </b>
</a>






I don't know how to express this kind of contextual constraint. Thanks a lot. 

Helka F.
Received on Wednesday, 9 June 2004 10:58:20 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:44 GMT