<?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 的代码:
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