- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Wed, 13 Mar 2002 12:30:50 +0000
- To: Joey Coyle <joey@xcoyle.com>
- CC: xmlschema-dev@w3.org
Hi Joey,
> I read in this list that this first example is OK, but is there a
> way to do this with a type other than "any". Instead of any, I would
> like my own type, then I would like to substitute derived types as
> is done here. My example is after the $$$$$$$$$$$$$$$$$$$$$$$$$, and
> I hope it is valid.
I'm afraid that what you have definitely isn't valid. When you do a
restriction, elements that are valid according to the restricted type
must also be valid according to the base type. In your case, if you
had:
<foo>
<e1 />
</foo>
which is valid according to your newtype:
> <complexType name="newtype">
> <complexContent>
> <restriction base="my:basetype">
> <sequence>
> <element name="e1" type="myTypeRestriction"/>
> <element name="e2" type="myTypeRestriction2" minOccurs="0"/>
> <element name="e3" type="myTypeRestriction3" minOccurs="0"/>
> </sequence>
> </restriction>
> </complexContent>
> </complexType>
it wouldn't be valid according to your base type, which only allows
'item' elements within the element:
> <complexType name="basetype">
> <sequence>
> <element name="item" type="myType" maxOccurs="unbounded"/>
> </sequence>
> </complexType>
The reason that you can do the restriction with the xs:any wildcard
is that the base type then allows any element.
What you could do, however, is create a substitution group for the
four elements, with 'item' as the head element. The elements have to
be declared globally, as follows:
<element name="item" type="myType" />
<element name="e1" type="myTypeRestriction" substitutionGroup="item" />
<element name="e2" type="myTypeRestriction2" substitutionGroup="item" />
<element name="e3" type="myTypeRestriction3" substitutionGroup="item" />
[Note that myTypeRestriction must be derived from MyType.]
You can then define your base type by referring to that item element:
<complexType name="basetype">
<sequence>
<element ref="item" maxOccurs="unbounded"/>
</sequence>
</complexType>
and likewise your newtype by referring to the global declarations of
the other elements:
<complexType name="newtype">
<complexContent>
<restriction base="my:basetype">
<sequence>
<element ref="e1" />
<element ref="e2" minOccurs="0"/>
<element ref="e3" minOccurs="0"/>
</sequence>
</restriction>
</complexContent>
</complexType>
This works because if you take account of the substitution group, the
basetype type definition is equivalent to:
<complexType name="basetype">
<sequence>
<choice maxOccurs="unbounded">
<element ref="item" />
<element ref="e1" />
<element ref="e2" />
<element ref="e3" />
</choice>
</sequence>
</complexType>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 13 March 2002 07:30:52 UTC