473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XPath and SQLXML

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
1 3003
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark Sisson | last post by:
Ok gurus, what would you do? I'm developing an app in C# and trying to use SqlXml but there seems to be a problem at every turn. I want to create a biz object that represents an order to sell a...
0
by: Ralph Krausse | last post by:
Hello all, Newbie here and have a few questions. I wish to use the classes SqlXmlAdapter,SqlXmlCommand,etc in my ASP.NET project but when I add 'using Microsoft.Data.SqlXml', the IDE doesn't see...
0
by: Nick Chan | last post by:
hello i exposed some stored procs as web methods, is there a way to use authentication? i just want to set only me can use it. And is there a way to save the SQLXML IIS Settings and export to...
0
by: Paula DiTallo | last post by:
Hello Techies-- I am reading an XML document with many nested elements. Many of these elements go to such a variety of tables, that I am trying to simply the read of the document by dumping the...
1
by: norm dingle | last post by:
Does anyone know how to get the managed classes for sqlxml loaded? I can not seem to get them to load. Thanks norm
3
by: David Elliott | last post by:
I am in the process of creating an application to scrape databases in order to create typed DataSets. One of the last pieces that I need to do is to remap database fields to something more...
4
by: Don | last post by:
Hi: When I read my sqlxml results into a reader and deserialize it, I only get the first record deserialized into my object. If I have five records, they're all in the reader. But how do I get...
1
by: campwes | last post by:
Hey, all! We're having trouble displaying SQL Server data in a web site as XML, using a transform. The query is a simple SELECT statement. When running the query, we get the following error from...
0
by: RJ | last post by:
I saw an article on MSDN knowledge base that explains how to use a SQLXML tool ( IIS Configuration ) to select a stored procedure and generate a web service wrapper. I noticed that the example to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.