-2

我需要分别获取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 中。谢谢你的帮助。

4

1 回答 1

2

以下是获取入站事务数的方法:

var xdoc = XDocument.Parse(xml);
var c = xdoc.Descendants("inbound").Descendants("transaction").Count();
于 2012-09-28T07:05:26.240 回答