Deriving complexTypes by restriction.

Guest

I am getting a strange error, maybe someone knows why it is occurring..

I get the following error when I try to validate Untitled8.xml in
Altova XMLSPY:

Validation error in another file: Untitled3.xsd

The message in XMLSPY in Untitled3.xsd is: The file is not valid: The
content model of complex type { no name } is not a valid restriction
of the content model of complex type 'Condiment_Type'

http://www.w3.org/TR/xmlschema-1/#cos-ct-derived-ok is pretty hairy
looking, but nothing jumps out at me as a reason why this might be so..
It's also wierd ( at least to me ) that when I open just Untitled3.xsd
and hit 'F8' to Validate that file that it validates fine, but when I
try to use Untitled3.xsd to validate Untitled8.xml the xsd is suddenly
not valid anymore..

Advertisements

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):

Advertisements

Guest

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..

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!