Hi
I'm stuck with the following schema validation problem in VS.NET 2003:
I have two types of xml document and related schema:
project and projectCollection.
A projectcollection is just a set of projects.
Therefore, I wish to include the project customType in the projectCollection
namespace.
I therefore have declared two xsd documents: project.xsd and
projectcollection.xsd
These both validate.
and two xml documents to test validation:
project.xml and projectcollection.xml.
project.xml validates perfectly, however all of the project tags within
projectcollection.xml are not validated.
Can anyone tell me where I'm going wrong?
Thanks.
Iain Mcleod
The documents are as follows:
project.xsd:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Project" targetNamespace="http://www.golds.co.uk/Project"
elementFormDefault="qualified"
xmlns="http://www.golds.co.uk/Project"
xmlns:mstns="http://www.golds.co.uk/Project"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="projectType">
<xs:sequence>
<xs:element name="projectDescription" minOccurs="0" maxOccurs="1" />
<xs:element name="projectMemberCollection" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="projectMember" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence />
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
<xs:key name="ProjectMemberNameKey">
<xs:selector xpath=".//mstns:projectMember" />
<xs:field xpath="@name" />
</xs:key>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:unsignedInt" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="version" type="xs:decimal" />
</xs:complexType>
<xs:element name="project" type="projectType" />
</xs:schema>
projectCollection.xsd:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="ProjectCollection"
targetNamespace="http://www.golds.co.uk/ProjectCollection"
elementFormDefault="qualified"
xmlns="http://www.golds.co.uk/ProjectCollection"
xmlns:mstns="http://www.golds.co.uk/ProjectCollection"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:projectNS="http://www.golds.co.uk/Project"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:import namespace="http://www.golds.co.uk/Project"
schemaLocation="Project.xsd" />
<xs:element name="projectCollection" type="projectCollectionType">
<xs:key name="ProjectPrimaryKey" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:project" />
<xs:field xpath="@id" />
</xs:key>
<xs:key name="ProjectNameVersionKey">
<xs:selector xpath=".//mstns:project" />
<xs:field xpath="@name" />
<xs:field xpath="@version" />
</xs:key>
</xs:element>
<xs:complexType name="projectCollectionType">
<xs:sequence>
<!-- Project Elements defined in Project.xsd -->
<xs:element name="project" type="projectNS:projectType" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:schema>
project.xml:
<?xml version="1.0" encoding="utf-8" ?>
<project xmlns="http://www.golds.co.uk/Project" id="1" name="PM"
version="1">
<projectDescription>Project Management</projectDescription>
<projectMemberCollection>
<projectMember name="GOLDS\PC" />
</projectMemberCollection>
</project>
projectCollection.xml:
<?xml version="1.0" encoding="utf-8"?>
<projectCollection xmlns="http://www.golds.co.uk/ProjectCollection">
<project id="1" name="PM" version="1.0">
<projectDescription>Project Management</projectDescription>
<projectMemberCollection>
<projectMember name="GOLDS\PC" />
</projectMemberCollection>
</project>
<project id="2" name="PM" version="1.1">
<projectDescription>This is a description</projectDescription>
<projectMemberCollection>
<projectMember name="GOLDS\PC" />
<projectMember name="GOLDS\IAM" />
</projectMemberCollection>
</project>
</projectCollection>