- From: Eddie Robertsson <eddie@allette.com.au>
- Date: Tue, 27 Nov 2001 09:51:18 +1100
- To: "Henry S. Thompson" <ht@cogsci.ed.ac.uk>
- CC: Martin Bernauer <bernauer@dke.uni-linz.ac.at>, 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> I'm still trying to get my head around all the rules for derivation by restriction but should the above Person type really be a derivation by extension from the base Object? I have two reasons for asking this question: 1) Since the base Object doesn't specify a type this means that it will default to the anyType. This in turn means that any element and any attribute is allowed so how can this type be extended to add elements and attributes? Shouldn't this be a restriction so you restrict the anyType to only allow the elements and attributes declared? > <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> 2) My second reason is because (from what I can understand) in the above restriction the intent is to use person elements instead of entry elements. Doesn't the rules on restriction say that for this to be valid then the type of the person element must be derived by _restriction_ from the type of the entry element. In this case the type of the person element (Person) is derived by _extension_ from the type of the entry element (Object). Cheers, /Eddie
Received on Monday, 26 November 2001 17:43:54 UTC