Re: Nested Schema

Hi Sameek,

> Want something like this
>
> <xs:element name="Menu">
>      <xs:complexType>
>        <xs:sequence>
>
>          <element name="File" type="xs:string"/>
>          <element name="Edit" type="xs:string"/>
>          <element name="Menu" type="xs:Menu"/> //***See this***//
>
>        </xs:sequence>
>      </xs:complexType>
> </xs:element>

You want the third element (Menu) in the content model to refer to the
global Menu element. To do that, you need the other form of xs:element
- with a ref attribute that refers to the global element, as follows:

<xs:element name="Menu">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="File" type="xs:string"/>
      <xs:element name="Edit" type="xs:string"/>
      <xs:element ref="Menu" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

When you do this kind of recursively nested schema, though, you should
always make sure that the recursive reference is *optional*.
Otherwise, the content model can never stop, and you can never create
an instance that satisfies it. So actually what you need is:

<xs:element name="Menu">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="File" type="xs:string"/>
      <xs:element name="Edit" type="xs:string"/>
      <xs:element ref="Menu" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

If you don't want Menu to be a global element, then you can do the
same kind of thing by declaring the *complexType* at the top level,
and referring to that when you fix the type of the local Menu element,
as follows:

<xs:element name="Menu" type="MenuType" />
<xs:complexType name="MenuType">
  <xs:sequence>
    <xs:element name="File" type="xs:string"/>
    <xs:element name="Edit" type="xs:string"/>
    <xs:element name="Menu" type="MenuType" minOccurs="0" />
  </xs:sequence>
</xs:complexType>

Cheers,

Jeni

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

Received on Thursday, 14 February 2002 02:51:48 UTC