Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Deriving complexTypes by restriction.

Reply
Thread Tools

Deriving complexTypes by restriction.

 
 
bclark76@gmail.com
Guest
Posts: n/a
 
      11-15-2005
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
xmlnssi="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 xmlnss="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>

 
Reply With Quote
 
 
 
 
Stan Kitsis [MSFT]
Guest
Posts: n/a
 
      11-15-2005
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


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
> xmlnssi="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 xmlnss="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>
>



 
Reply With Quote
 
 
 
 
bclark76@gmail.com
Guest
Posts: n/a
 
      11-16-2005

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
xmlnssi="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 xmlnss="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>

 
Reply With Quote
 
Henry S. Thompson
Guest
Posts: n/a
 
      11-16-2005
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
Reply With Quote
 
Stan Kitsis [MSFT]
Guest
Posts: n/a
 
      11-17-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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: (E-Mail Removed)
> URL: http://www.ltg.ed.ac.uk/~ht/
> [mail really from me _always_ has this .sig -- mail without it is forged
> spam]



 
Reply With Quote
 
bclark76@gmail.com
Guest
Posts: n/a
 
      11-18-2005
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: (E-Mail Removed)
> URL: http://www.ltg.ed.ac.uk/~ht/
> [mail really from me _always_ has this .sig -- mail without it is forged spam]


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
complexTypes versus elements John LaRusic XML 2 03-21-2007 09:19 PM
problem with complexTypes and arrayType in wsdl? DJShultz@gmail.com XML 0 06-21-2006 06:04 PM
is it possible to have a union of complextypes? sachin XML 1 12-02-2005 04:06 PM
repost-.Net XmlValidatingReader should fail on complextypes withwhitespace? Larry XML 1 06-10-2004 06:55 PM
.Net XmlValidatingReader should fail on complextypes with whitespace? Larry XML 0 06-04-2004 12:59 PM



Advertisments