Re: Derivation by restriction wrt to type inheritance

From: "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?
> 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>
>
My application needs an extension. Imagine you have a personList and a
staffList, then personList would allow persons, and staffList staff members
(and type of staff is derived by extension from type of person). Furthermore
it's better to give type Object a defined content model than anyType and to
derive by extension.

> 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 don't understand 2) neither, but due to antother reason (additionally to
the restriction problem mentioned above). I thought when deriving a type by
restriction the whole contents model of the base type must be repeated, and
I don't see an "entry" element in type personList. Especially as "entry" and
not "person" is the substitution group's head element. Does this really
work?
I think you should write <xs:element ref="entry"/> instead of <xs:element
ref="person"/>, but then it would not be a valid restriction. If it worked,
the problem with substitution groups would remain, that I could put any
element that is member of the "entry" substitution group into a personList,
e.g. a car, an airplane, etc.

Regards, Martin

> Cheers,
> /Eddie
>

Received on Tuesday, 27 November 2001 12:16:59 UTC