W3C home > Mailing lists > Public > xmlschema-dev@w3.org > October 2003

Re: Nested Substitutiongroups, how to?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 15 Oct 2003 10:05:24 +0100
Message-ID: <1641539663048.20031015100524@jenitennison.com>
To: "Svend Bent Nielsen" <jawsoap@hotmail.com>
Cc: xmlschema-dev@w3.org

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 GMT

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