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

Re: infinite loop

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 8 Jan 2003 09:44:03 +0000
Message-ID: <1521098669.20030108094403@jenitennison.com>
To: oliver fodor <fodor@itc.it>
CC: xmlschema-dev@w3.org

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 GMT

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