Re: Derivation by restriction wrt to type inheritance

"Henry S. Thompson" <ht@cogsci.ed.ac.uk> writes:

> The equivalent of templates, which is what you need for your List
> example, is indeed supported by XML Schema, using substitution groups:
>

You are right, it is somewhat a class-parameterization, as supported by C++
via templates.

>  <xs:complexType name="List">
>   <xs:sequence minOccurs="0" maxOccurs="unbounded">
>    <xs:element ref="entry"/>
>   </xs:sequence>
>  </xs:complexType>
>
>  <xs:element name="entry" abstract="true" type="Object"/>
>
> Note because this is abstract you will have to declare other elements
> which have this as their substitution group head.
>
>  <xs:complexType name="Object"/> [this could be anything you choose]
>
>  <xs:element name="list" type="List"/> [polymorphic list]
>
>  <xs:complexType name="Person">
>   <xs:complexContent>
>    <xs:extension base="Object">
>     <xs:sequence>
>      <xs:element name="name"/>
>      . . .
>     </xs:sequence>
>     <xs:attribute name="gender" type="xs:token"/>
>     . . .
>    </xs:extension>
>   </xs:complexContent>
>  </xs:complexType>
>
>  <xs:element name="person" type="Person" substitutionGroup="entry"/>
>
>  <xs:element name="personList">
>   <xs:complexType>
>    <xs:complexContent>
>     <xs:restriction base="List">
>      <xs:sequence minOccurs="0" maxOccurs="unbounded">
>       <xs:element ref="person"/>
>      </xs:sequence>
>     </xs:restriction>
>    </xs:complexContent>
>   </xs:complexType>
>  </xs:element>
>
> So this will allow <personList><person gender='F'><name>....</person>
>                                <person....
>                    </personList>
>
>  <xs:element name="company" substitutionGroup="entry">
>   <xs:complexType>
>    <xs:complexContent>
>     <xs:extension base="Object">
>      . . .
>     </xs:extension>
>    </xs:complexContent>
>   </xs:complexType>
>  </xs:element>
> </xs:schema>
>
> Now you could mix <person> and <company> inside a polymorphic <list>,
> or define a <companyList> in the same way as <personList>.
>

First of all thanks for your example. But unfortunately the problem remains
that different lists have different element names. When using templates or
class parameterization, the names of instance variables whose type is
changed still remains the same. But the use of substitution group forces me
to change the element's name (having in mind that an element is somehow the
same thing as an instance variable).
A motivation for keeping the same element names irrespective of the list's
type would be for example to be able to write code that performs generic
operations on lists, and to restrict the replacing type (Person) to a
subtype of the replaced type (Object).

Martin

> You could make the 'List' type abstract if you wanted to _require_
> restriction to lists of particular sub-types of Object.
>
> Hope this helps.
>
> 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 Tuesday, 27 November 2001 11:59:45 UTC