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

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - 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()函数时,增加名字空间。