Get a XmlNode from a Strongly Typed DatSet with XPath

G

Guest

Hi!

To get a XmlNode from an untyped DataSet with Path is no problem at all. It
works fine and gives you the expected node a long you use the rigth XPath
exprssion with SelectSingleNode. I've done that in many projekts succesfully
with untyped DataSets!

But now I am working with strongly typed DataSet and it does'nt work
anymore. When I save the XML with WriteXml(fileName) I can see clearly that
the only difference between the untyped and the strongly typed DatatSet is
the fact that the strongly typed DataSet uses a reference
xmlns:http://../mySchema.xsd as attribute in the document element.
That's the only difference. But that's seem to be the reason why I can't use
the same XPath expression to get a single or the first node by the
SelectSingleNode(9 method.

What can I do to solve the problem? I can't see the reason why I can't use
the already working xPath expression anymore because I am using an strongly
typed DataSet instead of an untyped DataSet.

What's the difference and how can I solve that problem?

Thank you fpr your help

Gerda
 
B

Bart Mermuys

Hi,

Gerda said:
Hi!

To get a XmlNode from an untyped DataSet with Path is no problem at all.
It
works fine and gives you the expected node a long you use the rigth XPath
exprssion with SelectSingleNode. I've done that in many projekts
succesfully
with untyped DataSets!

But now I am working with strongly typed DataSet and it does'nt work
anymore. When I save the XML with WriteXml(fileName) I can see clearly
that
the only difference between the untyped and the strongly typed DatatSet is
the fact that the strongly typed DataSet uses a reference
xmlns:http://../mySchema.xsd as attribute in the document element.

That means that "http://../mySchema.xsd" is a default namespace and XPath
doesn't know about default namespaces, you need to fully qualify your XPath
parts with a prefix that reference the default namespace.

Eg:

XmlDocument doc = new XmlDocument();
doc.Load("somedataset.xml");

XmlNamespaceManager xmgr =
new XmlNamespaceManager(doc.NameTable);

// create a namespace prefix "def" and get the
// namespace uri from the document node
xmgr.AddNamespace( "def",
doc.DocumentElement.NamespaceURI );

// qualify all xpath parts with the namespace prefix, eg:
XmlNode node = doc.SelectSingleNode(
"/def:TestDataSet/def:table1[1]/def:Name", xmgr);


HTH,
Greetings
 
C

Cor Ligthert [MVP]

Gerda,

Are you talking about accessing the dataset at serverside using document
methods?

If that is true, why are you than not using the methods from the dataset
itself or its objects as datatable, dataview, datarow, datarelation?

Cor
 

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

Top