group or abstract type?

I'm on the way to replace a DTD by an XSD and to enhance it by more appropriate constraints and so on.
The XML documents contain menu structures consisting of menu entries, which themselves consist of
menu entries. Simplified the XSD looks like that:

<xs:element name="MenuStructure">
  <xs:complexType>
    <xs:sequence>
      <xs:choice maxOccurs="unbounded">
        <xs:element ref="MenuEntry"/>
        <xs:element ref="DynamicMenuEntry"/>
        <xs:element ref="Spacer"/>
      </xs:choice>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:element name="MenuEntry">
  <xs:complexType>
    <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="MenuEntry"/>
        <xs:element ref="DynamicMenuEntry"/>
        <xs:element ref="Spacer"/>
      </xs:choice>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:element name="DynamicMenuEntry">
  <xs:complexType>
    ......
  </xs:complexType>
</xs:element>
<xs:element name="Spacer">
  <xs:complexType/>
</xs:element>

So the <xs:choice .... </xs:choice> part is dublicated. To simplify (and to express that it's really 2 times the same)
I'd like to consolidate it and I see two possibilities to do so:
1. I extract the part, add and use it as a group:

<xs:group name="SomeMenu">
  <xs:choice>
    <xs:element ref="MenuEntry"/>
    <xs:element ref="DynamicMenuEntry"/>
    <xs:element ref="Spacer"/>
  </xs:choice>
</xs:group>
...
<xs:element name="MenuStructure">
  <xs:complexType>
    <xs:sequence>
      <xs:group ref="SomeMenu" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

2. Specify a abstract type and substitute it in the concrete menu entries:
<xs:element name="AbstractMenuEntry" abstract="true"/>
...
<xs:element name="MenuStructure">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="AbstractMenuEntry" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
...
<xs:element name="MenuEntry" substitutionGroup="AbstractMenuEntry">
  ...
and so on

What are the advantages and disadvantages of both solutions? Are there recommendations on what should
be preferred under certain circumstances? I could imagine that if part of the schema (i.e. the group/abstract type) would be
external and not modifiable for those who wanted to add new concrete menu entries, the choice should be the abstract type,
however in my situation this is not the case.

Thanks for any help, hints, and links
pat

Received on Tuesday, 8 January 2002 10:59:41 UTC