【发布时间】:2013-01-24 09:40:38
【问题描述】:
在 machine.config 文件中有一些由 3rd 方软件编写的元素,因此看起来像这样:
<configuration>
<configSections>
...
</configSections>
...
<Custom>
<Level1> ...
</Level1>
<Level2> ...
</Level2>
<Level3>
<add key="key_text1" value="s1" />
<add key="key_text2" value="s2" />
<add key="key_text3" value="s3" />
</Level3>
</Custom>
</configuration>
我想得到例如“value”属性的值(“s2”),其中 key="key_text2" 来自 configuration/Custom/Level3 节点。到目前为止,我尝试将 machine.config 作为 XML 打开并从那里开始工作:
Configuration config = ConfigurationManager.OpenMachineConfiguration();
XmlDocument doc = new XmlDocument();
doc.LoadXml(config.FilePath);
但是,我收到 XmlException“根级别的数据无效。”。我也不知道如何直接使用配置类方法来完成这项工作。任何想法将不胜感激。
【问题讨论】:
标签: c# .net xml xmldocument machine.config