I have the following XSD created in VS.NET 2003:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral"
elementFormDefault="unqualified"
xmlns="http://test.org/Referral" xmlns:mstns="http://test.org/Referral"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:complexType name="ReferralType">
<xs:sequence>
<xs:element name="nReferralId" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int"/>
<xs:element name="nPersonId" type="xs:int"/>
<xs:element name="nReferralNumber" type="xs:int"/>
<xs:element name="dReferralDate" type="xs:dateTime"/>
<xs:element name="dDateOfBirth" type="xs:dateTime"/>
<xs:element name="dDateOfDeath" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Document">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="tReferral" type="mstns:ReferralType"/>
</xs:choice>
</xs:complexType>
<xs:unique name="ReferralKey" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:tReferral"/>
<xs:field xpath="mstns:nReferralId"/>
</xs:unique>
</xs:element>
</xs:schema>
and am attempting to load it via the SqlXmlAdapter in SQLXML3.0 as follows:
try
{
SqlXmlCommand cmd = new SqlXmlCommand(ConnString);
cmd.RootTag = "ROOT";
cmd.CommandText = txtXPath.Text;
cmd.CommandType = SqlXmlCommandType.XPath;
cmd.SchemaPath = "..\\..\\ReferralSchama.xsd";
//load data set
DataSet ds = new DataSet();
SqlXmlAdapter ad = new SqlXmlAdapter(cmd);
ad.Fill(ds);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
I've attempting to use various XPath statements such as the following to
load the data, but it fails with the following exception every time:
"XPath: unable to find /XXXXX in the schema".
XPath tried:
tReferral
tDocument/tReferral
Document/tReferral/nReferralId=1
tReferral/nReferralId=1
Document/tReferral/[@nReferralId=1]
tReferral/[@nReferralId=1]
Anyone know what I'm doing wrong?