我需要分别计算inbound
次交易和outbound
次交易。我已经尝试了所有我知道的东西,但没有任何工作。这是XML:
<?xml version="1.0" encoding="utf-8"?>
<records>
<inbound>
<transaction>
<customerID>0002</customerID>
<customerName>bob</customerName>
</transaction>
<transaction>
<customerID>0003</customerID>
<customerName>harry</customerName>
</transaction>
.
.
.
<transaction>
<customerID>0250</customerID>
<customerName>joe</customerName>
</transaction>
</inbound>
<outbound>
<transaction>
<customerID>0002</customerID>
<customerName>bob</customerName>
</transaction>
<transaction>
<customerID>0003</customerID>
<customerName>harry</customerName>
</transaction>
.
.
.
<transaction>
<customerID>0175</customerID>
<customerName>frank</customerName>
</transaction>
</outbound>
</records>
这需要在C#和LINQ中。谢谢你的帮助。
答案 0 :(得分:2)
以下是获取inbounds的交易次数的方法:
var xdoc = XDocument.Parse(xml);
var c = xdoc.Descendants("inbound").Descendants("transaction").Count();