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

XPath and SQLXML

P: n/a
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?
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You haven't included the namespace. Use the SqlXmlCommand's Namespaces
property to reference the http://test.org/Referral namespace (see Executing
XPath Queries with Namespaces in the SQLXML .NET Framework Support > SQLXML
Managed Classes > Using the SQLXML Managed Classes topic of the SQLXML 3.0
docs).

Hope that heps,
Graeme

--
----
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Hollywood" <ho*******@thzero.com> wrote in message
news:uZ***************@TK2MSFTNGP09.phx.gbl...
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?

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.