<?xml version="1.0" encoding="utf-8"?>
<OrdersReport Date="2012-08-01">
<Returns>
<Amount>
<OrderId>2</OrderId>
<OrderId>3</OrderId>
<OrderId>21</OrderId>
<OrderId>23</OrderId>
</Amount>
</Returns>
</OrdersReport>
這是我想獲得的OrderId代碼:的LINQ to XML沒有得到所有節點
var amount = doc.Descendants("Amount")
.Select(y => new
{
OrderId = (int)y.Element("OrderId")
});
foreach (var r in amount)
{
Console.WriteLine(r.OrderId);
}
Console.Read();
我的輸出是:
2
2
+1 ....簡單的方法來得到它direcly .. –