c# 选择单节点 xpath 返回 null

标签 c# xpath

我在 C# 项目中有一个应用程序配置,我需要在运行时进行编辑。作为其中的一部分,我有一个自定义部分集合,我需要为其选择一个节点。这是我的即时窗口中的 xml 和选择语句:

node = xmlDoc.SelectSingleNode("//Customers/add[@id='1']");  

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="customers" type ="ImporterSupport.CustConfigSection, ImporterSupport"/>
    </configSections>
    <customers>
        <add id ="1" license="gh620g0g0g0g0g3p" ServerAddress ="localhost"  ServerPort="8292" SettingsFile ="AutoImportTest.txt" Confirm ="false" DisableRemoveRecips="true" DisableRecoverRecips="true" DisableAlphaId ="true" />
    </customers>
</configuration>

最佳答案

Xml 区分大小写。使用

var node = xmlDoc.SelectSingleNode("//customers/add[@id='1']");

关于c# 选择单节点 xpath 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31813884/

相关文章:

xpath - jaxb 绑定(bind)文件中的这个 XPath 表达式有什么问题?

java - 如何使用 Selenium 和 Java 单击“确认”按钮

c# - ASP.NET MVC 发布模型始终为空

xpath - 使用xpath帮助从HTML表中提取文本

xml - XSLT 中的累积变量

xslt - 如何在 XPath 中查找所有空子树

c# - 在 C# 中使用 GitLabCI

c# - ServiceStack、LeftJoin 查询

Java Base64.getDecoder().decode() C# 等效项

c# - 为什么我会收到此消息 : "items collection must be empty before using itemssource" in a treeview?