xml文件内容如下:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<applicationSettings>
<test1.Properties.Settings>
<setting name= 'AppConnection' value=''/>
</test1.Properties.Settings>
</applicationSettings>
</configuration>
取值的代码:
string configFileName = Application.ExecutablePath + ".config";
MessageBox.Show(configFileName);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(configFileName);
string configString = @"configuration/applicationSettings/test1.Properties.Settings/setting[@name='AppConnection']/value";
System.Xml.XmlNode configNode = doc.SelectSingleNode(configString);
在最后的 configNode 那里总是取不到值。大神帮忙看一下问题出在哪儿
你的value是属性,不是节点,当然选不出,去掉/value
string configString = @"configuration/applicationSettings/test1.Properties.Settings/setting[@name='AppConnection']";
System.Xml.XmlNode configNode = doc.SelectSingleNode(configString);
MessageBox.Show(configNode != null && configNode.Attributes["value"] != null ? configNode.Attributes["value"].Value : "NULL");
请用MarkDown的代码段格式贴代码:前后个加一行,内容是三个反单引号(键盘1键左边的键)。