- From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
- Date: 27 Nov 2001 18:48:06 +0000
- To: Eddie Robertsson <eddie@allette.com.au>
- Cc: Martin Bernauer <bernauer@dke.uni-linz.ac.at>, xmlschema-dev@w3.org
Eddie Robertsson <eddie@allette.com.au> writes:
> > 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?
Yes, because that's what the questioner asked for.
> 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.
Nope. _Element declarations_ with no type get the ur-type by
default. Complex type definitions default to _restrictions_ of the
ur-type [1], and since they're empty, that in turn defaults to an
empty content model.
> This in turn means that any element and any attribute is allowed so
> how can this type be extended to add elements and attributes?
Since it's empty, extension is the right thing.
<snip/>
> 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).
I agree this is confusing, but it's correct. The base type allows a
sequence of any number of <entry> elts. Since <entry> is the head of
a substitution group, this effectively is a sequence of any number of
choices among the members of that s-group, i.e. <person> or
<company>. So a type which allows only a sequence of <person> is
indeed a restriction.
ht
[1] http://www.w3.org/TR/xmlschema-1/#declare-type
--
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 13:47:03 UTC