有人可以用正确的 LINQ 语法帮助我从这个 XML 中提取状态吗?
理想情况下,我希望打印出以下内容:
状态:打开=1
状态:待定=2
状态:忽略=3
状态:关闭=4
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<scope name="com">
<scope name="company">
<scope name="app">
<scope name="app_monitor">
<scope name="statuses">
<entry name="Open">1</entry>
<entry name="Pending">2</entry>
<entry name="Ignored">3</entry>
<entry name="Closed">4</entry>
</scope>
<scope name="urgencies">
<entry name="Critical">1</entry>
<entry name="Alarm">2</entry>
<entry name="Info">3</entry>
</scope>
</scope>
</scope>
</scope>
</scope>
</configuration>
我尝试了不同的变化,但这是我得到了多远:
XDocument Xdocument = new XDocument();
var doc = XDocument.Load(@"c:\temp\app_sett.xml");
var returnedvalues = from app_sett in doc.Descendants("scope")
where app_sett.Attribute("name").Value == "statuses"
select new
{
blah = app_sett.Attribute("name").Value,
};