Using xs:import and xs:extension

R

randar

I'm having problems getting an XML document to validate against a
fairly complex scenario.

Goals:
-To have two schemas with two different namespaces, so that I can
validate each one seperately against an XML doc. Hence why I'm using
xs:import instead of xs:include.
-To create some sample XML that will validate in Visual Studio and I
can use the tools there to enter in the XML data.

Here is the "base" schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="BaseSchema" targetNamespace="http://tempuri.org/Program"
elementFormDefault="qualified" xmlns="http://tempuri.org/Program"
xmlns:mstns="http://tempuri.org/Program"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="BaseElement" type="BaseComplexType">
</xs:element>
<xs:complexType name="BaseComplexType">
<xs:sequence>
<xs:element name="Primary" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Here is the sub schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="SubSchema"
targetNamespace="http://tempuri.org/ProgramSub"
elementFormDefault="qualified" xmlns="http://tempuri.org/ProgramSub"
xmlns:mstns="http://tempuri.org/ProgramSub"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:bs="http://tempuri.org/Program"
xmlns:ss="http://tempuri.org/ProgramSub">
<xs:import schemaLocation="BaseSchema.xsd"
namespace="http://tempuri.org/Program"></xs:import>
<xs:element name="SubElement" type="SubComplexType">
</xs:element>
<xs:complexType name="SubComplexType">
<xs:complexContent>
<xs:extension base="bs:BaseComplexType">
<xs:sequence>
<xs:element name="ExtraString" type="xs:string" />
<xs:element name="Foo" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

Both of these seem to validate fine. When I create a new XML document
using VS, the data entry tools work fine and it generates:
<?xml version="1.0" encoding="utf-8"?>
<SubElement xmlns="http://tempuri.org/ProgramSub">
<Primary xmlns="http://tempuri.org/Program">1</Primary>
<ExtraString>sad</ExtraString>
<Foo>asdfasd</Foo>
</SubElement>

But it gives me the validation error of:
C:\Projects\Miscellaneous\Prototypes\ProgramManagement\Test.xml(3): The
active schema does not support the element 'Primary'.

So I tried to put namespaces in:
<?xml version="1.0" encoding="utf-8"?>
<ss:SubElement xmlns:ss="http://tempuri.org/ProgramSub"
xmlns:bs="http://tempuri.org/Program">
<bs:primary>1</bs:primary>
<ss:ExtraString>sd</ss:ExtraString>
<ss:Foo>sad</ss:Foo>
</ss:SubElement>

But still no luck.
C:\Projects\Miscellaneous\Prototypes\ProgramManagement\SubData.xml(3):
The active schema does not support the element 'bs:primary'.

Anybody have an idea?
 
H

Henry S. Thompson

Works for me.

That is, I can validate your instance with your schema docs just fine,
using XSV.

Sounds like a VS bug.

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 address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
S

Stan Kitsis [MSFT]

VS2005 validates it as well.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top