我在 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/