tags:

views:

78

answers:

1

Consider the following:

<xs:complexType name="A">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:group ref="subAGroup"/>
        <xs:group ref="xGroup"/>
    </xs:choice>
</xs:complexType>
<xs:complexType name="B">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:group ref="subBGroup"/>
        <xs:group ref="xGroup"/>
    </xs:choice>
</xs:complexType>

What I want to happen is if one of the elements in the xGroup is a child, grandchild, etc. of A then its children must be part of the subAGroup or xGroup. If B is its ancestor then its children must be in the subBGroup or xGroup.

A: 

One solution is to create different groups and types for each parent type. To follow the example above, it would become this:

<xs:complexType name="A">
 <xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:group ref="subAGroup"/>
  <xs:group ref="xGroup"/>
 </xs:choice>
</xs:complexType>
<xs:complexType name="B">
 <xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:group ref="subBGroup"/>
  <xs:group ref="yGroup"/>
 </xs:choice>
</xs:complexType>

<xs:group name="xGroup">
 <xs:choice>
  <xs:element name="Element1" type="AEleType"/>
 </xs:choice>
</xs:group>
<xs:complexType name="AEleType">
 <xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:group ref="subAGroup"/>
  <xs:group ref="xGroup"/>
 </xs:choice>
</xs:complexType>

<xs:group name="yGroup">
 <xs:choice>
  <xs:element name="Element1" type="BEleType"/>
 </xs:choice>
</xs:group>
<xs:complexType name="BEleType">
 <xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:group ref="subBGroup"/>
  <xs:group ref="yGroup"/>
 </xs:choice>
</xs:complexType>

It seems overly verbose though. Is there a more elegant solution?

Jataro