【发布时间】:2019-09-12 11:39:42
【问题描述】:
我需要获取缺少特定参数的 xml 节点。假设我有以下 c:\temp\a.xml:
<files>
<file product="myproduct">C:\file_myproduct</file>
<file>C:\file_general</file>
</files>
如何获取没有属性的 C:\file_general 值?我试过了:
var doc = new XmlDocument();
doc.Load(@"c:\temp\a.xml");
// C:\file_myproduct - good
string myproduct = doc.SelectSingleNode("/files/file[@product='myproduct']").InnerText;
// I need C:\file_general here, but this gives again the C:\file_myproduct
string general = doc.SelectSingleNode("/files/file").InnerText;
【问题讨论】: