Re: infinite loop

Hi Oliver,

> does the XML Schema specification allow the following combination of
> complex types? it might lead to an infinite loop ...
>
> <xs:complexType name="bType" mixed="true">
>         <xs:choice minOccurs="0" maxOccurs="unbounded">
>                 <xs:element name="i" type="iType" />
>                 <xs:element name="ul" type="ulType" />
>         </xs:choice>
> </xs:complexType>
>
> <xs:complexType name="iType" mixed="true">
>         <xs:choice minOccurs="0" maxOccurs="unbounded">
>                 <xs:element name="b" type="bType" />
>                 <xs:element name="ul" type="ulType" />
>         </xs:choice>
> </xs:complexType>

This schema is fine, just as its DTD equivalent of:

  <!ELEMENT b (#PCDATA | i | ul)*>
  <!ELEMENT i (#PCDATA | b | ul)*>

is just fine, and indeed very useful; it allows <i> and <b> elements
to be nested inside each other to any depth. See the HTML DTD for
loads of examples where this is used.

The important point about the above is that the <i> and <b> elements
are both optional within the content models, which means that no
matter how deep the nesting you can eventually have an <i> or <b>
element that *doesn't* contain a nested <b> or <i> element. I thought
you were going to ask whether:

  <xs:element name="E" type="T" />
  <xs:complexType name="T">
    <xs:sequence>
      <xs:element ref="E" />
    </xs:sequence>
  </xs:complexType>

was legal. In this schema, every <E> element must have an <E> element
nested inside it, which means that it's impossible to create an XML
document that satisfies the schema. There's nothing to stop you from
creating these schemas, though of course you won't be able to write
any documents that are valid against it.

Cheers,

Jeni

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

Received on Wednesday, 8 January 2003 04:44:19 UTC