urgent help

  • Thread starter Thread starter John Lee
  • Start date Start date
J

John Lee

Hi,

I have a document
<root>
<name>John</name>
</root>
and the xpath "//name" will return correct node by using
xmldoc.SelectSingleNode(xpath)

and if the document contains a default namespace
<root xmlns="mynamespace">
<name>John</name>
</root>
the xpath "//name" no longer returns the <name> node

Please help!!!

Thanks very much!
John
 
hmm if i remember correctly, you need to qualify your xpath with the
namespace:

xpath = "mynamespace://name"

And you also might need to use an XML NamespaceManager in your app.
 
Hi John,

Here is a simple example that can make it work. HTH.

XmlDocument doc = new XmlDocument();
doc.LoadXml("<root xmlns=\"mynamespace\"><name>John</name></root>");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("v", "mynamespace");
XmlNode node = doc.SelectSingleNode("//v:name", nsmgr);

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