By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,469 Members | 1,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,469 IT Pros & Developers. It's quick & easy.

Deriving complexTypes by restriction.

P: n/a
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..

Any thoughts would be appreciated. Thanks.

Here is my xml file that I am trying to validate ( Untitled8.xml ) :

<?xml version="1.0" encoding="UTF-8"?>
<PeanutButterSandwich
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Untitled3.xsd">
<Bread>wheat</Bread>
<Condiment>
<PeanutButter>Jiffy</PeanutButter>
</Condiment>
</PeanutButterSandwich>
Here is my xsd ( Untitled3.xsd ) :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="Condiment_Type">
<xs:choice>
<xs:element name="Jelly"/>
<xs:element name="PeanutButter"/>
<xs:element name="Ketchup"/>
<xs:element name="Mustard"/>
<xs:element name="Mayo"/>
</xs:choice>
</xs:complexType>
<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:complexType name="Sandwich_Type">
<xs:sequence>
<xs:element name="Bread">
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment" type="Condiment_Type"/>
<xs:element name="FoodSlice" type="FoodSlice_Type"/>
</xs:choice>
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Condiment_Sandwich_Type">
<xs:complexContent>
<xs:restriction base="Sandwich_Type">
<xs:sequence>
<xs:element name="Bread">
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment" type="Condiment_Type"/>
</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 name="Bread">
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="Condiment_Type">
<xs:choice>
<xs:element name="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:schema>

Nov 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
<bc******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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..

Any thoughts would be appreciated. Thanks.

Here is my xml file that I am trying to validate ( Untitled8.xml ) :

<?xml version="1.0" encoding="UTF-8"?>
<PeanutButterSandwich
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Untitled3.xsd">
<Bread>wheat</Bread>
<Condiment>
<PeanutButter>Jiffy</PeanutButter>
</Condiment>
</PeanutButterSandwich>
Here is my xsd ( Untitled3.xsd ) :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="Condiment_Type">
<xs:choice>
<xs:element name="Jelly"/>
<xs:element name="PeanutButter"/>
<xs:element name="Ketchup"/>
<xs:element name="Mustard"/>
<xs:element name="Mayo"/>
</xs:choice>
</xs:complexType>
<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:complexType name="Sandwich_Type">
<xs:sequence>
<xs:element name="Bread">
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment" type="Condiment_Type"/>
<xs:element name="FoodSlice" type="FoodSlice_Type"/>
</xs:choice>
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Condiment_Sandwich_Type">
<xs:complexContent>
<xs:restriction base="Sandwich_Type">
<xs:sequence>
<xs:element name="Bread">
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment" type="Condiment_Type"/>
</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 name="Bread">
<xs:simpleType>
<xs:restriction base="xs:normalizedString">
<xs:enumeration value="white"/>
<xs:enumeration value="wheat"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="Condiment">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="Condiment_Type">
<xs:choice>
<xs:element name="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:schema>

Nov 23 '05 #2

P: n/a

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:xsi="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:xs="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>

Nov 23 '05 #3

P: n/a
XSV is happy with your revised schema document, and it looks OK to me
by eye, so I suggest you file a bug report with your tool vendor.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Nov 23 '05 #4

P: n/a
System.xml (.NET 2.0) also has no problems with the schema (or the
instance).

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

"Henry S. Thompson" <ht@inf.ed.ac.uk> wrote in message
news:f5*************@erasmus.inf.ed.ac.uk...
XSV is happy with your revised schema document, and it looks OK to me
by eye, so I suggest you file a bug report with your tool vendor.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged
spam]

Nov 23 '05 #5

P: n/a
Thanks to both of you who replied. I sent a bug report to Altova
referencing this post.

Henry S. Thompson wrote:
XSV is happy with your revised schema document, and it looks OK to me
by eye, so I suggest you file a bug report with your tool vendor.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]


Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.