基本的に、私は次のようなxmlファイル形式を持っています:
<?xml version="1.0" encoding="utf-8" ?>
<retentions>
<client id="1544">
<facility id="5436">
<retention period="23" />
</facility>
</client>
<client id="7353">
<facility id="3450">
<retention period="3" />
</facility>
</client>
</retentions>
「1554」、「5436」、「23」など、すべての属性のすべての値を取得したい。
XMLDocument の代わりに XDocument を使用してください。私のコードは間違っています:
XDocument XDoc = XDocument.Load("my.xml");
IEnumerable<XElement> results = (from el in XDoc.Root.Elements("retentions")
select el);
更新:(辞書を使用)
var g = from element in XDoc.Descendants("client")
from ID in element.Attributes("id")
from Facility in element.Attributes("facility")
from Period in element.Attributes("period")
select new { Key = ID.Value, Value = Period.Value };