W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2001

Re: Element occurence

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 20 Jun 2001 14:05:09 +0100
To: "Wouter Cordewiner" <wouter_cordewiner@hotmail.com>
Cc: xmlschema-dev@w3.org
Message-ID: <f5bbsnj9u9m.fsf@cogsci.ed.ac.uk>
"Wouter Cordewiner" <wouter_cordewiner@hotmail.com> writes:

> I have following XML file:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation='schema.xsd'>
>   <level4 id1='1'></level4>
>   <level4 id1='2'></level4>
>   <level4 id1='3'></level4>
>   <level4 id1='4'></level4>
>   <level5 id2='1'></level5>
>   <level5 id2='2'></level5>
>   <level5 id2='3'></level5>
>   <level4 id1='1'></level4>
> </result>
> 
> All elements under the <result> element should be optional, and they can occur
> multiple times.
> 
> In other words, the DTD representation of what I would like to accomplish is :
> 
> 
> <!ELEMENT result ((level4?)*,(level5?)*,(level4?)*)>

This DTD is also broken -- a validating parser would reject it for
ambiguity.  If all you want is literally what you say above, the DTD
would be 

  <!ELEMENT result (level4|level5)*>

If you want something more like what you have above, then it's

  <!ELEMENT result (level4*,level5+,level4*)>

The first becomes

 <xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:element ref="level4"/>
  <xs:element ref="level5"/>
 </xs:choice>

The second becomes

  <xs:sequence>
   <xs:element ref="level4" minOccurs="0" maxOccurs="unbounded"/>
   <xs:element ref="level5" minOccurs="1" maxOccurs="unbounded"/>
   <xs:element ref="level4" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
Received on Wednesday, 20 June 2001 09:05:08 GMT

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