Re: Recursion in an XML Schema

Hi Matthew,

> I figure the easiest way to do this is to use recursion in the XML
> schema to say something like:
>
> <schema>
>     <complexType name="SectionType">
>         <sequence>
>             <element name="section" type="SectionType">
>               <annotation>
>                   <documentation>Recursive</documentation>
>               </annotation>
>             </element>
>         </sequence>
>     </complexType>
>     <element name="section" type="SectionType"/>
> </schema>
>
> is this a valid method of using recursion inside a schema, and if
> not, how can I go about doing it?

That's a valid way to do it. The one thing you have to be a little
careful of is the fact that the section element declared at the top
level of the document is subtly different from the section element
declared inside the complex type. In particular, the section element
declared within the complex type might not be qualified (depending on
what you've done with the elementFormDefault), but this is only a
worry if you dealing with namespaces.

Of course there are several alternative designs that do the same
thing. You could reference the global element declaration from within
the complex type definition:

<complexType name="SectionType">
  <sequence>
    <element ref="section" />
  </sequence>
</complexType>

And you could make the complex type definition anonymous:

<element name="section">
  <complexType>
    <sequence>
      <element ref="section" />
    </sequence>
  </complexType>
</element>

Cheers,

Jeni

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

Received on Thursday, 1 November 2001 05:10:13 UTC