-2

次のネストされたループがあります

foreach (XmlNode nodeT in root.ChildNodes)
{
    foreach (XmlNode nodeServicio in nodeT.ChildNodes)
    {
        nombreMayusculas = nodeServicio.Name.ToUpper();

        if (nombreMayusculas.Contains("SERVICE"))
        {
            int a = 0;
            int.TryParse(nombreMayusculas.Replace("SERVICE", ""), out a);

            if (a.Equals(Type))
            {
                  //some logic here to process only the matching Xmlnode
            }
        }
    }
}

編集 両方の条件に一致する一致する XmlNodes のみをループする方法はありますか?

私はWherelinqメソッドを使用しようとしましたが、利用できず、すでに持っていますusing System.Linq

ここにXMLがあります

<Clients>
    <AgoraCOR1 Type=\"SP\" Default=\"False\">
        <Connectionstring>CONN_STRING</Connectionstring>
        <Service002>SaveOperationNotification</Service002>
        <Service106>SaveOrderNotification</Service106>
    </AgoraCOR1>
    <SerficorpOrdenes1 Type=\"SP\" Default=\"False\">
        <Connectionstring>CONN_STRING</Connectionstring>
        <Service106>SaveOrderNotification</Service106>
        <Service017>SaveComplementationNotification</Service017>
    </SerficorpOrdenes1>
    <CorrevalCORInterno1 Type=\"SP\" Default=\"False\">
        <Connectionstring>CONN_STRING</Connectionstring>
        <Service002>SaveOperationNotification</Service002>
        <Service074>SaveIndicatorNotification</Service074>
        <Service106>SaveOrderNotification</Service106>
        <Service017>SaveComplementationNotification</Service017>
        <Service072>SalvarNotificacionPreciosDeMercado</Service072>
    </CorrevalCORInterno1>
</Clients>
4

3 に答える 3

0

Linq を使用できますが、既に行ったことと同じパフォーマンス プロファイルになります。

var nodesToProcess = root
    .ChildNodes
    .ChildNodes
    .Where(n => n.Name.ToUpper().Contains("SERVICE")));

foreach(var node in nodesToProcess)
{
    ....
}
于 2013-09-09T13:57:38.467 に答える