W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > July to September 2000

Re: extension vs restriction

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 08 Sep 2000 11:08:17 +0100
To: "Zar Zar Tun" <zarzar@dstc.edu.au>
Cc: <www-xml-schema-comments@w3.org>
Message-ID: <f5bn1hj6vse.fsf@cogsci.ed.ac.uk>
"Zar Zar Tun" <zarzar@dstc.edu.au> writes:

> Wouldn't it get just a bit hairy if we had to repeat all the elements and
> attributes of the base type if we wanted to do a derivation by restriction?
> 
> For example, the base type could itself be derived by extension from another
> type, e.g.
> 
> type 1
>         element 1 minOccurs = 0 maxOccurs=1
>         element 2 minOccurs = 0 maxOccurs=1
>         element 3 minOccurs = 0 maxOccurs=1
> 
> type 2 derives from type 3 by extension
>         element 4 minOccurs = 0 maxOccurs=1
>         element 5 minOccurs = 0 maxOccurs=1
> 
> Do we also have to declare the elements inherited from super type of the
> base type, such as
> 
> type 3 derives from type 4 by restriction
>         element 1 minOccurs = 0 maxOccurs=1
>         element 2 minOccurs = 0 maxOccurs=1
>         element 3 minOccurs = 0 maxOccurs=1
>         element 4 minOccurs = 0 maxOccurs=1
>         element 5 minOccurs = 0 maxOccurs=0
> 
> If so, then it could get really ugly. A type could be part of a long type
> hierarchy chain. Then, you would have to look up all the ancestors that a
> type derives from, and do a tedious copy-and-paste job. Also, types can be
> derived from types in other files through import/include statements, which
> makes it more inconvenient. And you may have to go through all this effort
> to just change one small item in a declaration.
> 
> Has this been resolved? I'm probably repeating what others may have pointed
> out. And if so, what is the new situation on derivation by restriction? I'd
> also like to know how derivation by restriction would work with groups -
> attribute groups, model groups, group components - but that's opening
> another can of worms.

Actually, that's not another can of worms, that's the solution.

No, we haven't changed the necessity of repeating the whole model in
order to restrict it.  Yes, that's tedious, but the WG decided it was
the best compromise between clarity and conciseness.  Use of groups is 
fine, and mitigates the problem, here's your example recast for this
purpose:

<group name="s1">
 <sequence>
  <element ref='1' minOccurs ='0' maxOccurs='1'/>
  <element ref='2' minOccurs ='0' maxOccurs='1'/>
  <element ref='3' minOccurs ='0' maxOccurs='1'/>
 </sequence>
</group>

<complexType name="t1">
  <group ref="s1"/>
</complexType>


<group name="s2">
 <sequence>
  <element ref='4' minOccurs ='0' maxOccurs='1'/>
  <element ref='5' minOccurs ='0' maxOccurs='1'/>
 </sequence>
</group>

<complexType name='t2' base='t1' derivedBy='extension'>
 <group ref='s2'/>
</complexType>

<group name="s2r">
 <sequence>
  <element ref='4' minOccurs ='0' maxOccurs='1'/>
  <element ref='5' minOccurs ='0' maxOccurs='0'/>
 </sequence>
</group>

<complexType name='t3' base='t2' derivedBy='restriction'>
 <sequence>
  <group ref='s1'/>
  <group ref='s2r'/>
 </sequence>
</complexType>

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 Friday, 8 September 2000 06:08:21 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:49:53 UTC