W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2002

Re: Several same elements

From: Eddie Robertsson <erobertsson@allette.com.au>
Date: Tue, 20 Aug 2002 10:31:10 +1000
Message-ID: <3D618DCE.4050906@allette.com.au>
To: Cyrill Zadra <czadra@bluewin.ch>
CC: xmlschema-dev@w3.org

Hi Cyrill,

> Is it possible to have an xml struktur like below, or do you have any 
> better ideas to solve such a structure? 

Sure.

> <chapter id=""><!-- chapter name -->
>    <chapter id=" "><!-- chapter name --></chapter>
>    <chapter id=" "></chapter>
>    <chapter id=" ">
>        <chapter id=" "></chapter>
>    </chapter>
> </chapter>
>
> If it would be possible how could i describe this in xml-schema? The 
> way I first thought its actually not THE solution. I'm looking for an 
> short and simple possibility to solve this problem. 

What you need is a recursive content model and this can be expressed 
like this:

<xsd:element name="chapter" type="chapterType"/>

<xsd:complexType name="chapterType">
    <xsd:sequence>
        <xsd:element name="chapter" type="chapterType" minOccurs="0" 
maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="idcheck"/>
</xsd:complexType>

However, if you do it this way you can't control the number of chapter 
elements that can appear on each level. If you need to do this you have 
to specify one complexType for each level. Also, note that you must have 
minOccurs="0" on the "inner" chapter element otherwise you'll get an 
infinite content model that parsers can't handle.

Cheers,
/Eddie
Received on Monday, 19 August 2002 20:16:10 GMT

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