Stan Kitsis [MSFT] wrote:
> Element <Bread> in your derived types has to be either of the same type or
> of a type derived from <Bread> element's type in the base type. In your
> case, however, both elements define their own anonymous types. Even though
> the types look the same, they are treated as distinct and independent types.
> This makes your derivations invalid. You need to define a global simple
> type for this element and reference it from all types (base and derived):
>
> <xs:simpleType name="breadType">
> <xs:restriction base="xs:normalizedString">
> <xs:enumeration value="white"/>
> <xs:enumeration value="wheat"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:element Bread type="breadType"/>
>
> --
> Stan Kitsis
> Program Manager, XML Technologies
> Microsoft Corporation
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
>
>
Thanks for the reply. I did not know that types that were defined the
same but not explicitly given the same name were considered different
types. With that in mind. I re-did the xsd so that all my types (
hopefully ) were explicitly named and all my elements explicitly
referenced a named type (except for the Condiment element in
PeanutButter_Sandwich_Type ).
My new Untitled3.xsd is posted below.
But I still get the error that Untitled3.xsd is invalid when used to
validate Untitled8.xml, only now it says: "The content model of complex
type PeanutButter_Condiment_Type is not a valid restriction of the
content model of complex type Condiment_Type."
Some background:
I am trying to model the fact that every PeanutButterSandwich isa valid
Sandwich. I would like for any element that validates as a
PeanutButterSandwich to also validate as a Sandwich.
So PeanutButter_Sandwich_Type is a restriction of Sandwich_Type.
Because PeanutButter is a condiment in this example, I define a
PeanutButter_Condiment_Type to be a restriction of Condiment_Type where
the only valid choice is PeanutButter. As a restriction of
Sandwich_Type, PeanutButter_Sandwich_Type will only allow Condiments
and no FoodSlices. This is why PeanutButter_Sandwich_Type is a
restriction of Condiment_Sandwich_Type. But PeanutButter_Sandwich_Type
has the further restriction that the Condiment element must conform not
to the general definition of Condiment_Type which allows
Ketchup/Mustard/etc, but to PeanutButter_Condiment_Type which only
allows PeanutButter as a choice. This means that a new 'Condiment'
element of PeanutButter_Condiment_Type that does not reference the
previously defined Condiment element of Condiment_Type is defined
within the definition of PeanutButter_Sandwich_Type.
This, maybe, is the heart of my problem: PeanutButter_Sandwiches are a
subset of Condiment_Sandwiches. Both may have a Condiment element, but
they are of different types ( Condiment_Type for Sandwiches of type
Condiment_Sandwich_Type, and PeanutButter_Condiment_Type for
PeanutButter_Sandwiches ) However, PeanutButter_Condiment_Type is a
restriction of Condiment_Type, so the Condiment element of any valid
PeanutButter_Sandwich is guaranteed to be a valid Condiment element for
a sandwich of type Condiment_Sandwich_Type. But the error message
says that PeanutButter_Condiment_Type is not a valid restriction of
Condiment_Type. It is odd that the error seems to be with the
Condiment_Type and PeanutButter_Condiment_Type definitions rather than
with the Condiment_Sandwich_Type and PeanutButter_Sandwich_Types..
Here is Untitled8.xml again:
<?xml version="1.0" encoding="UTF-8"?>
<PeanutButterSandwich
xmlns

si="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Untitled3.xsd">
<Bread>wheat</Bread>
<Condiment>
<PeanutButter>Jiffy</PeanutButter>
</Condiment>
</PeanutButterSandwich>
And here is the new Untitled3.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2006 sp1 U (
http://www.altova.com) by Bonehead
Mcgee (TDBanknorth) -->
<xs:schema xmlns

s="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="Bread_Type">
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="Bread" type="Bread_Type"/>
<xs:complexType name="Condiment_Type">
<xs:choice>
<xs:element ref="Jelly"/>
<xs:element ref="PeanutButter"/>
<xs:element ref="Ketchup"/>
<xs:element ref="Mustard"/>
<xs:element ref="Mayo"/>
</xs:choice>
</xs:complexType>
<xs:element name="Condiment" type="Condiment_Type"/>
<xs:complexType name="PeanutButter_Condiment_Type">
<xs:complexContent>
<xs:restriction base="Condiment_Type">
<xs:choice>
<xs:element ref="PeanutButter"/>
</xs:choice>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="PeanutButter_Condiment">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="PeanutButter_Condiment_Type">
<xs:choice>
<xs:element ref="PeanutButter"/>
</xs:choice>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:complexType name="FoodSlice_Type">
<xs:choice>
<xs:element name="Balogna"/>
<xs:element name="Cheese"/>
<xs:element name="Onions"/>
<xs:element name="Tomatos"/>
</xs:choice>
</xs:complexType>
<xs:element name="FoodSlice" type="FoodSlice_Type"/>
<xs:complexType name="Sandwich_Type">
<xs:sequence>
<xs:element ref="Bread"/>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element ref="Condiment"/>
<xs:element ref="FoodSlice"/>
</xs:choice>
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:element name="Sandwich" type="Sandwich_Type"/>
<xs:complexType name="Condiment_Sandwich_Type">
<xs:complexContent>
<xs:restriction base="Sandwich_Type">
<xs:sequence>
<xs:element ref="Bread"/>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element ref="Condiment"/>
</xs:choice>
</xs:sequence>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="PeanutButter_Sandwich_Type">
<xs:complexContent>
<xs:restriction base="Condiment_Sandwich_Type">
<xs:sequence>
<xs:element ref="Bread"/>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="PeanutButter_Condiment_Type">
<xs:choice>
<xs:element ref="PeanutButter"/>
</xs:choice>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:element name="PeanutButterSandwich"
type="PeanutButter_Sandwich_Type"/>
<xs:element name="PeanutButter"/>
<xs:element name="Jelly"/>
<xs:element name="Ketchup"/>
<xs:element name="Mustard"/>
<xs:element name="Mayo"/>
</xs:schema>