一段含有命名空间的Xml:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?>
<LinkLibrary xmlns:xsd="QuanShiZiMu" >
<Link Cat="aa" Url="_aa" />
<Link Cat="bb" Url="_bb" />
<Link Cat="cc" Url="_cc" />
<Link Cat="dd" Url="_dd" />
<Link Cat="ee" Url="_ee" >哈哈</Link>
</LinkLibrary>
<LinkLibrary xmlns:xsd="QuanShiZiMu" >
<Link Cat="aa" Url="_aa" />
<Link Cat="bb" Url="_bb" />
<Link Cat="cc" Url="_cc" />
<Link Cat="dd" Url="_dd" />
<Link Cat="ee" Url="_ee" >哈哈</Link>
</LinkLibrary>
(1) 搜索InnerText为哈哈的节点
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable);
xnm.AddNamespace("xmlns:xsd", "QuanShiZiMu");
XmlNodeList xnl = doc.SelectNodes("//LinkLibrary[Link='哈哈']", xnm);
doc.LoadXml(xml);
XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable);
xnm.AddNamespace("xmlns:xsd", "QuanShiZiMu");
XmlNodeList xnl = doc.SelectNodes("//LinkLibrary[Link='哈哈']", xnm);
(2) 搜索某属性为dd的节点
XmlNodeList xnl = doc.SelectNodes("//LinkLibrary/Link[@Cat='ee']", xnm);