惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - james.dong

初次使用T4引擎生成数据库表实体 - james.dong - 博客园 加快大表关联查询的速度(oracle) DataTable 排序 - james.dong - 博客园 查询oracle数据库中所有视图和表的信息 日期验证正规表达式( YYYY-MM-DD YYYY-MM-DD hh:mm:ss YYYY/MM/DD) windows2000server下 iis 无法下载 .exe , .dll文件的解决办法。 - james.dong C#中datagridview使用技巧系列谈(-)让输入焦点从左到右收藏 oracle中创建自增字段 .net 序列化和反序列化自定义treenode类 LotusScript基础知识(二) LotusScript基本语法知识(一) LotusScript中Option 的含义 Lotusscript中Instr()函数的功能和用法 Combox控件实现类似TextBox控件的ReadOnly=true时的背景颜色和字体颜色!(WinForm) WPF 中的 BitmapEffect 的 各种样式 WPF相关文章汇总 使用List泛型,怎么排序 asp.net2.0解决用户控件图片相对路径出错的问题,ResolveUrl的用法 window.showModalDialog()时没有显示修改后的数据 - james.dong - 博客园
System.Xml.XmlDocument.SelectNodes() 查询不到节点问题? - james.dong - 博客园
james.dong · 2008-10-31 · via 博客园 - james.dong

今天在使用xmldocument.selectnodes()函数时遇到查询满足一定条件的节点时,无法查找到相应的节点。

后来google了一下,原来是自定义名字空间惹的祸。

下面是xml文件内容:

<?xml version="1.0" encoding="utf-8"?>

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">

 <aaaa>

   <bbbb>1234</bbb>

   <bbbb>4567</bbbb>

   <bbbb>8989</bbbb>

</Report>

-----------------------------------------------------------------------------------------

using System.Xml;

public class aaaa

{

    public void Search1()

   {//我用下列代码查询 无节点

      XmlDocument xmlDoc = new  XmlDocument();

        xmlDoc.Load("*.xml");

        string filter = "//*[contains(bbbb,'8989']";

        XmlnodeList list = xmlDoc.SelectNodes(filter);//此处查询的节点个数为0

   }

   public void Search2()

   {//用这个方法就可以查询到了

      XmlDocument xmlDoc = new  XmlDocument();

        xmlDoc.Load("*.xml");

        XmlNamespaceManager m = new XmlNamespaceManager ( xmldoc.NameTable );

        m.AddNamespace("ab",

"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");

        string filter = "//ab:*[contains(ab:bbbb,'8989']";

        XmlnodeList list = xmlDoc.SelectNodes(filter);//此处查询的节点个数为1

   } 

}

当使用xmldocument.selectnodes()时,如果xml文件中有自定义的名字空间的话,在使用selectnodes()函数时,增加名字空间。