473,322 Members | 1,241 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Deriving complexTypes by restriction.

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
5 1637
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

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Steven T. Hatton | last post by:
This may be another question having an obvious answer, but I'm not seeing it. I'm trying to create a class that derives from std::valarray<std::string>. I don't need a template, and I haven't come...
0
by: Paula DiTallo | last post by:
Hello Techies-- I am reading an XML document with many nested elements. Many of these elements go to such a variety of tables, that I am trying to simply the read of the document by dumping the...
0
by: Deep Purple | last post by:
I started with the following error... ------------------------------------------------------- An error occured while loading the schema with TargetNamespace 'http://www.w3.org/2001/XMLSchema'...
0
by: DJShultz | last post by:
My problem is that c# seems to get nothing back from this wsdl (source below) and I'm wondering if I'm writing it wrong? sample xml returned is also below. Can someone please either tell me what...
9
by: arun.hallan | last post by:
I need to derive fractions from decimals as so: 0.3333 = 1/3 0.6666 = 2/3 The decimal could also be 0.33, or 0.3333333 but the point is that it that the fraction needs to be extracted. ...
15
by: Nindi73 | last post by:
HI If I define the class DoubleMap such that struct DoubleMap : public std::map<std::string, double>{}; Is there any overhead in calling std::map member functions ? Moreover are STL...
6
by: burkley | last post by:
In XML Schema, is it possible to derive a complex type via restriction and have the new derived type be in a different namespace than the original base type? I've banged on this for 2 days now...
0
by: Andrew 2006 | last post by:
I have a wsdl definition that includes the following definition for the element <Preferencesinside the request createFooBar: <xs:element minOccurs="1" name="Preferences" nillable="true"...
3
by: vainstah | last post by:
Hello Guys and Galls, To start off, I have reached the solution I was looking for, but I would like comments and feedback on the solution I have reached and tips/tricks on making it more elegant....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.