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

vs2003 & xsd:extension

P: n/a
Hello,

I have already read several existing posts about xsd:extension, but do not
find something useful to my test case. I have one xml file and one xsd file.
I can use a simple command line (C#) program to validate the xml file against
the xsd file without any error. The problem is that when I validate the same
xml file within VisualStudio 2003, I got five errors, which are all related
to xsd:extension. It seems that those "problem" attributes and elements are
not inherited in the derived type. Here is one of the famous error:

Could not find any attribute 'routingNum' of element 'hat'.

Any input is appreciated much. Thanks.

The following are the xml file and the xsd:

<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall PTR -->
<c:items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://chapter14.xsd
http://localhost/xsd/chapter14.xsd"
xmlns:c="http://chapter14.xsd">
<hat routingNum="123456" effDate="2002-04-02" lang="en-US">
<number>557</number>
<name>Ten-Gallon Hat</name>
<description>This is a great hat!</description>
</hat>
<umbrella routingNum="123" effDate="2002-04-02">
<number>557</number>
<name>Ten-Gallon Hat</name>
</umbrella>
<shirt routingNum="124" effDate="2002-04-02" sleeve="17">
<number>557</number>
<name>Short-Sleeved Linen Blouse</name>
<color value="blue"/>
<size system="US-DRESS">6</size>
</shirt>
</c:items>

---------------------------------------------------
<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall PTR -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://chapter14.xsd"
xmlns="http://chapter14.xsd">

<xsd:annotation>
<xsd:documentation>
This example illustrates complex types that are derived from other
specified types.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="items" type="ItemsType"/>

<xsd:complexType name="ItemsType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="hat" type="ProductType"/>
<xsd:element name="umbrella" type="RestrictedProductType"/>
<xsd:element name="shirt" type="ShirtType"/>
</xsd:choice>
</xsd:complexType>

<!--Empty Content Type-->
<xsd:complexType name="ItemType" abstract="true">
<xsd:attribute name="routingNum" type="xsd:integer"/>
</xsd:complexType>

<!--Empty Content Extension (with Attribute Extension)-->
<xsd:complexType name="ProductType">
<xsd:complexContent>
<xsd:extension base="ItemType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="effDate" type="xsd:date"/>
<xsd:attribute name="lang" type="xsd:language"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Restriction-->
<xsd:complexType name="RestrictedProductType">
<xsd:complexContent>
<xsd:restriction base="ProductType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:token"/>
</xsd:sequence>
<xsd:attribute name="routingNum" type="xsd:short" use="required"/>
<xsd:attribute name="effDate" type="xsd:date" default="1900-01-01"/>
<xsd:attribute name="lang" use="prohibited"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Extension-->
<xsd:complexType name="ShirtType">
<xsd:complexContent>
<xsd:extension base="RestrictedProductType">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="size" type="SmallSizeType"/>
<xsd:element name="color" type="ColorType"/>
</xsd:choice>
<xsd:attribute name="sleeve" type="xsd:integer"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Simple Content Extension-->
<xsd:complexType name="SizeType">
<xsd:simpleContent>
<xsd:extension base="xsd:integer">
<xsd:attribute name="system" type="xsd:token"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

<!--Simple Content Restriction-->
<xsd:complexType name="SmallSizeType">
<xsd:simpleContent>
<xsd:restriction base="SizeType">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="6"/>
<xsd:attribute name="system" type="xsd:token"
use="required"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="ColorType">
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>

</xsd:schema>

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Your xml and xsd validate fine with the validation engine in VS 2003. Are
you putting your schema file in the right location?

"man-in-nature" <ma*********@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
Hello,

I have already read several existing posts about xsd:extension, but do not
find something useful to my test case. I have one xml file and one xsd file. I can use a simple command line (C#) program to validate the xml file against the xsd file without any error. The problem is that when I validate the same xml file within VisualStudio 2003, I got five errors, which are all related to xsd:extension. It seems that those "problem" attributes and elements are not inherited in the derived type. Here is one of the famous error:

Could not find any attribute 'routingNum' of element 'hat'.

Any input is appreciated much. Thanks.

The following are the xml file and the xsd:

<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall PTR --> <c:items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://chapter14.xsd
http://localhost/xsd/chapter14.xsd"
xmlns:c="http://chapter14.xsd">
<hat routingNum="123456" effDate="2002-04-02" lang="en-US">
<number>557</number>
<name>Ten-Gallon Hat</name>
<description>This is a great hat!</description>
</hat>
<umbrella routingNum="123" effDate="2002-04-02">
<number>557</number>
<name>Ten-Gallon Hat</name>
</umbrella>
<shirt routingNum="124" effDate="2002-04-02" sleeve="17">
<number>557</number>
<name>Short-Sleeved Linen Blouse</name>
<color value="blue"/>
<size system="US-DRESS">6</size>
</shirt>
</c:items>

---------------------------------------------------
<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall PTR --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://chapter14.xsd"
xmlns="http://chapter14.xsd">

<xsd:annotation>
<xsd:documentation>
This example illustrates complex types that are derived from other
specified types.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="items" type="ItemsType"/>

<xsd:complexType name="ItemsType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="hat" type="ProductType"/>
<xsd:element name="umbrella" type="RestrictedProductType"/>
<xsd:element name="shirt" type="ShirtType"/>
</xsd:choice>
</xsd:complexType>

<!--Empty Content Type-->
<xsd:complexType name="ItemType" abstract="true">
<xsd:attribute name="routingNum" type="xsd:integer"/>
</xsd:complexType>

<!--Empty Content Extension (with Attribute Extension)-->
<xsd:complexType name="ProductType">
<xsd:complexContent>
<xsd:extension base="ItemType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string" minOccurs="0"/> </xsd:sequence>
<xsd:attribute name="effDate" type="xsd:date"/>
<xsd:attribute name="lang" type="xsd:language"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Restriction-->
<xsd:complexType name="RestrictedProductType">
<xsd:complexContent>
<xsd:restriction base="ProductType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:token"/>
</xsd:sequence>
<xsd:attribute name="routingNum" type="xsd:short" use="required"/>
<xsd:attribute name="effDate" type="xsd:date" default="1900-01-01"/> <xsd:attribute name="lang" use="prohibited"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Extension-->
<xsd:complexType name="ShirtType">
<xsd:complexContent>
<xsd:extension base="RestrictedProductType">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="size" type="SmallSizeType"/>
<xsd:element name="color" type="ColorType"/>
</xsd:choice>
<xsd:attribute name="sleeve" type="xsd:integer"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Simple Content Extension-->
<xsd:complexType name="SizeType">
<xsd:simpleContent>
<xsd:extension base="xsd:integer">
<xsd:attribute name="system" type="xsd:token"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

<!--Simple Content Restriction-->
<xsd:complexType name="SmallSizeType">
<xsd:simpleContent>
<xsd:restriction base="SizeType">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="6"/>
<xsd:attribute name="system" type="xsd:token"
use="required"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="ColorType">
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>

</xsd:schema>

Nov 12 '05 #2

P: n/a
I'm having the same problem with attributes from base types showing up
properly in the derived type in VS.NET 2003. VS understands the rest of the
schema, so it's finding the schema. It just doesn't seem to recognize
attributes from the base type of an xs:extension'ed type.
"man-in-nature" <ma*********@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
Hello,

I have already read several existing posts about xsd:extension, but do not
find something useful to my test case. I have one xml file and one xsd file. I can use a simple command line (C#) program to validate the xml file against the xsd file without any error. The problem is that when I validate the same xml file within VisualStudio 2003, I got five errors, which are all related to xsd:extension. It seems that those "problem" attributes and elements are not inherited in the derived type. Here is one of the famous error:

Could not find any attribute 'routingNum' of element 'hat'.

Any input is appreciated much. Thanks.

The following are the xml file and the xsd:

<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall PTR --> <c:items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://chapter14.xsd
http://localhost/xsd/chapter14.xsd"
xmlns:c="http://chapter14.xsd">
<hat routingNum="123456" effDate="2002-04-02" lang="en-US">
<number>557</number>
<name>Ten-Gallon Hat</name>
<description>This is a great hat!</description>
</hat>
<umbrella routingNum="123" effDate="2002-04-02">
<number>557</number>
<name>Ten-Gallon Hat</name>
</umbrella>
<shirt routingNum="124" effDate="2002-04-02" sleeve="17">
<number>557</number>
<name>Short-Sleeved Linen Blouse</name>
<color value="blue"/>
<size system="US-DRESS">6</size>
</shirt>
</c:items>

---------------------------------------------------
<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall PTR --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://chapter14.xsd"
xmlns="http://chapter14.xsd">

<xsd:annotation>
<xsd:documentation>
This example illustrates complex types that are derived from other
specified types.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="items" type="ItemsType"/>

<xsd:complexType name="ItemsType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="hat" type="ProductType"/>
<xsd:element name="umbrella" type="RestrictedProductType"/>
<xsd:element name="shirt" type="ShirtType"/>
</xsd:choice>
</xsd:complexType>

<!--Empty Content Type-->
<xsd:complexType name="ItemType" abstract="true">
<xsd:attribute name="routingNum" type="xsd:integer"/>
</xsd:complexType>

<!--Empty Content Extension (with Attribute Extension)-->
<xsd:complexType name="ProductType">
<xsd:complexContent>
<xsd:extension base="ItemType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string" minOccurs="0"/> </xsd:sequence>
<xsd:attribute name="effDate" type="xsd:date"/>
<xsd:attribute name="lang" type="xsd:language"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Restriction-->
<xsd:complexType name="RestrictedProductType">
<xsd:complexContent>
<xsd:restriction base="ProductType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:token"/>
</xsd:sequence>
<xsd:attribute name="routingNum" type="xsd:short" use="required"/>
<xsd:attribute name="effDate" type="xsd:date" default="1900-01-01"/> <xsd:attribute name="lang" use="prohibited"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Extension-->
<xsd:complexType name="ShirtType">
<xsd:complexContent>
<xsd:extension base="RestrictedProductType">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="size" type="SmallSizeType"/>
<xsd:element name="color" type="ColorType"/>
</xsd:choice>
<xsd:attribute name="sleeve" type="xsd:integer"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Simple Content Extension-->
<xsd:complexType name="SizeType">
<xsd:simpleContent>
<xsd:extension base="xsd:integer">
<xsd:attribute name="system" type="xsd:token"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

<!--Simple Content Restriction-->
<xsd:complexType name="SmallSizeType">
<xsd:simpleContent>
<xsd:restriction base="SizeType">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="6"/>
<xsd:attribute name="system" type="xsd:token"
use="required"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="ColorType">
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>

</xsd:schema>

Nov 12 '05 #3

P: n/a
Yes, VS2003 can find the schema in question. It never complains that "Visual
Studio could not locate a schema for this document...". It is easy to verify
this by changing the target name space in the instance document
("xmlns:c="http://chanpter14.xsd") to something else.

Regards

"Zafar Abbas [MSFT]" wrote:
Your xml and xsd validate fine with the validation engine in VS 2003. Are
you putting your schema file in the right location?

"man-in-nature" <ma*********@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
Hello,

I have already read several existing posts about xsd:extension, but do not
find something useful to my test case. I have one xml file and one xsd

file.
I can use a simple command line (C#) program to validate the xml file

against
the xsd file without any error. The problem is that when I validate the

same
xml file within VisualStudio 2003, I got five errors, which are all

related
to xsd:extension. It seems that those "problem" attributes and elements

are
not inherited in the derived type. Here is one of the famous error:

Could not find any attribute 'routingNum' of element 'hat'.

Any input is appreciated much. Thanks.

The following are the xml file and the xsd:

<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall

PTR -->
<c:items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://chapter14.xsd
http://localhost/xsd/chapter14.xsd"
xmlns:c="http://chapter14.xsd">
<hat routingNum="123456" effDate="2002-04-02" lang="en-US">
<number>557</number>
<name>Ten-Gallon Hat</name>
<description>This is a great hat!</description>
</hat>
<umbrella routingNum="123" effDate="2002-04-02">
<number>557</number>
<name>Ten-Gallon Hat</name>
</umbrella>
<shirt routingNum="124" effDate="2002-04-02" sleeve="17">
<number>557</number>
<name>Short-Sleeved Linen Blouse</name>
<color value="blue"/>
<size system="US-DRESS">6</size>
</shirt>
</c:items>

---------------------------------------------------
<!--Definitive XML Schema by Priscilla Walmsley (c) 2001 Prentice Hall

PTR -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://chapter14.xsd"
xmlns="http://chapter14.xsd">

<xsd:annotation>
<xsd:documentation>
This example illustrates complex types that are derived from other
specified types.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="items" type="ItemsType"/>

<xsd:complexType name="ItemsType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="hat" type="ProductType"/>
<xsd:element name="umbrella" type="RestrictedProductType"/>
<xsd:element name="shirt" type="ShirtType"/>
</xsd:choice>
</xsd:complexType>

<!--Empty Content Type-->
<xsd:complexType name="ItemType" abstract="true">
<xsd:attribute name="routingNum" type="xsd:integer"/>
</xsd:complexType>

<!--Empty Content Extension (with Attribute Extension)-->
<xsd:complexType name="ProductType">
<xsd:complexContent>
<xsd:extension base="ItemType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"

minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="effDate" type="xsd:date"/>
<xsd:attribute name="lang" type="xsd:language"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Restriction-->
<xsd:complexType name="RestrictedProductType">
<xsd:complexContent>
<xsd:restriction base="ProductType">
<xsd:sequence>
<xsd:element name="number" type="xsd:integer"/>
<xsd:element name="name" type="xsd:token"/>
</xsd:sequence>
<xsd:attribute name="routingNum" type="xsd:short" use="required"/>
<xsd:attribute name="effDate" type="xsd:date"

default="1900-01-01"/>
<xsd:attribute name="lang" use="prohibited"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

<!--Complex Content Extension-->
<xsd:complexType name="ShirtType">
<xsd:complexContent>
<xsd:extension base="RestrictedProductType">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="size" type="SmallSizeType"/>
<xsd:element name="color" type="ColorType"/>
</xsd:choice>
<xsd:attribute name="sleeve" type="xsd:integer"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<!--Simple Content Extension-->
<xsd:complexType name="SizeType">
<xsd:simpleContent>
<xsd:extension base="xsd:integer">
<xsd:attribute name="system" type="xsd:token"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>

<!--Simple Content Restriction-->
<xsd:complexType name="SmallSizeType">
<xsd:simpleContent>
<xsd:restriction base="SizeType">
<xsd:minInclusive value="2"/>
<xsd:maxInclusive value="6"/>
<xsd:attribute name="system" type="xsd:token"
use="required"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="ColorType">
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>

</xsd:schema>


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.