Re: Nested Substitutiongroups, how to?

Hi Svend,

> I have an element "Section" which can contain other "Section" as well as
> "Comment".
>      Section
>       |       \
> Comment   Section
>                   |       \
>              Section   Comment
>
> That is, Comment is a leaf node and can not ever contain other than
> text (simpletype).
>
> How would I make a substitutionGroup that explains this?
> Or is the below method the right way of doing this?
>
> <xs:element name="Section">
>   <xs:complextype>
>     <xs:choice>
>       <xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
>       <xs:element name="Comment" type="xs:string" minOccurs="0" 
> maxOccurs="unbounded"/>
>     </xs:choice>
>   </xs:complextype>
> </xs:element>

This is probably roughly the right method to do this: substitution
groups are for when you want a set of elements with similar content to
be interchangeable. Note that you want the minOccurs/maxOccurs
attributes to appear on the <xs:choice> rather than on the element
declarations (to say that there can be any number of <Section> and
<Comment> children, in any order):

<xs:element name="Section">
  <xs:complextype>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="Section"/>
      <xs:element name="Comment" type="xs:string"/>
    </xs:choice>
  </xs:complextype>
</xs:element>

> What if "Section" can also contain "_SmallGroup" (from earlier)? How
> can I write that?

Something like:

<xs:element name="Section">
  <xs:complextype>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="Section"/>
      <xs:element ref="_SmallGroup"/>
      <xs:element name="Comment" type="xs:string"/>
    </xs:choice>
  </xs:complextype>
</xs:element>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Wednesday, 15 October 2003 05:05:38 UTC