- From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
- Date: 26 Nov 2001 10:02:54 +0000
- To: "Martin Bernauer" <bernauer@dke.uni-linz.ac.at>
- Cc: <xmlschema-dev@w3.org>
The equivalent of templates, which is what you need for your List
example, is indeed supported by XML Schema, using substitution groups:
<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>.
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 Monday, 26 November 2001 05:01:51 UTC