0

I have a set of certain elements encapsulated in a complexType that are required if a user wants to do business in a certain way (lets call this way x):

<xs:element name="us">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="usAttribute1" type="xs:string"/>
      <xs:element name="commonAttribute1" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

and a certain set of elements encapsulated in a different complexType that are required if the user wants to do business in a different way (lets call this way y):

<xs:element name="uk">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="ukAttribute1" type="xs:string"/>
      <xs:element name="commonAttribute1" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

There is an overlap of elements between both sets such that some elements are common to both sets. Let's say that the user would like to do business in both way x and way y. How do we combine the two sets of elements so that there isn't any duplication of elements?

HGandhi
  • 1,586
  • 2
  • 14
  • 27

2 Answers2

1

You don't give any sample code, so it is difficult to say what you exactly want to solve and how, but it sounds like you could try using <xs:group> element.

Form a group of the common elements that contains the element's requirements and then refer to this group from your two complex types at a proper moment.

jasso
  • 13,736
  • 2
  • 36
  • 50
1

What you want is basically "multiple inheritance" in XML Schema.

It is not possible directly (you derive from one type only), but there are options:

  • You can use model groups (xs:group, xs:attributeGroup), you can reference several of them (credit goes to @jasso). From what I read in the specification, you should be able to include the commonAttribute1 element two times as long as the inclusion is more or less identical.
  • You may want to use aggregation instead of inheritance. It is often a better and easier approach.
lexicore
  • 42,748
  • 17
  • 132
  • 221