XmlDataDoc on DataSet - all SelectNodes fail.

C

Corey Wirun

Hi All,

I'm building an XmlDataDocument list this:

XmlDataDocument xmlDocResults = new XmlDataDocument( dsResults );
XmlNodeList nodes1 = xmlDocResults.SelectNodes(
"//RPDCY_TDataSet/RPDCY_T" );

No matter what XPath expression I put in the SelectNodes, I get a NodeList
back (i.e not null), but it's always Count = 0. Thinking something was
wrong with my DataSet, I 'dumped' it to a XML file so I could load it up in
XMLSpy and try the XPath same expression:

dsResults.WriteXml( @"e:\temp\ResultDataSet.xml" ) gives me:

<?xml version="1.0" standalone="yes"?>
<RPDCY_TDataSet xmlns="http://tempuri.org/RPDCY_TDataSet.xsd">
<RPDCY_T>
<DBINDEX>10001</DBINDEX>
<TAG>FI01002</TAG>
<DESCRIPT>Crude Unit Offgas to Sats Gas Unit</DESCRIPT>
<OFFSET>15</OFFSET>
<CORY>0</CORY>
<SRC_DBINDEX>10000</SRC_DBINDEX>
</RPDCY_T>
...
</RPDCY_TDataSet>

My XPath expression worked in XMLSpy - got a node list back. I also had a
look at xmlDocResults.InnerXml and sure enough, I saw the same XML.

So then I wrote a little subroutine that dumps out all the tables and rows -
all the rows have a row status as 'Unmodified'. So that can't be it.

Can anyone give me a little insight as to what is happening here? I've got
other XmlDataDoc's floating around, but I don't see this problem anywhere
else.

Thanks in Advance!
Corey.
 
K

Kevin Yu [MSFT]

Hi Corey,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you cannot get the node list using
XmlDataDocument.SelectNodes() method. If there is any misunderstanding,
please feel free to let me know.

Based on the code you have provided, it seems that you cannot get the node
list because you didn't include namespace in your code. So the SelectNodes
method is searching the the default namespace and cannot get your node.
Here I have made some changes to your code. HTH.

XmlDataDocument xmlDocResults = new XmlDataDocument(dsResults);
XmlNamespaceManager nsmgr = new
XmlNamespaceManager(xmlDocResults.NameTable);
nsmgr.AddNamespace("sche", "http://tempuri.org/RPDCY_TDataSet.xsd");
XmlNodeList nodes1 =
xmlDocResults.SelectNodes("//sche:RPDCY_TDataSet/sche:RPDCY_T", nsmgr);

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
C

Corey Wirun

Worked perfectly. Thanks.

I guess my other XmlDataDocuments worked because they were against untyped
DataSets - which used the default namespace.

C.
 

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

Similar Threads


Top