MainClass .cs
---------------------------
using System;
using System.Windows.Forms;
using System.Xml;namespace all
{ public class MainClass
{
[STAThread]
static void Main()
{
XmlDocument doc = new System.Xml.XmlDocument();
doc.Load("x.xml");
XmlNamespaceManager manager1 = new XmlNamespaceManager(doc.NameTable);
manager1.AddNamespace("Nikens", "http://www.nike.com");
XmlNode node1 = doc.DocumentElement.SelectSingleNode("Nikens:Model", manager1); if (node1 == null){
Console.WriteLine("node1 is null");
} Console.WriteLine("Finish");
Console.Read();
}
}
}
--------------------------------
x.xml
<?xml version="1.0" encoding="utf-8"?>
<Model xmlns="http://www.nike.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Class assembly="Datanike" type="Gove">
</Class>
</Model>
--------------------------------------------------
---------------------------
using System;
using System.Windows.Forms;
using System.Xml;namespace all
{ public class MainClass
{
[STAThread]
static void Main()
{
XmlDocument doc = new System.Xml.XmlDocument();
doc.Load("x.xml");
XmlNamespaceManager manager1 = new XmlNamespaceManager(doc.NameTable);
manager1.AddNamespace("Nikens", "http://www.nike.com");
XmlNode node1 = doc.DocumentElement.SelectSingleNode("Nikens:Model", manager1); if (node1 == null){
Console.WriteLine("node1 is null");
} Console.WriteLine("Finish");
Console.Read();
}
}
}
--------------------------------
x.xml
<?xml version="1.0" encoding="utf-8"?>
<Model xmlns="http://www.nike.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Class assembly="Datanike" type="Gove">
</Class>
</Model>
--------------------------------------------------
XmlNode node1 = doc.DocumentElement.SelectSingleNode("//Nikens:Model", manager1);
你是对的.
node1找到了node.