0

1つのキーに対して複数の値があるため、リストでネストされたxmlファイルから辞書を作成したい。私がこれに使用しているコードの下に -

  for (int i = 0; i < NumberOfVariation; i++)
    {
        SingleVariationDom.LoadXml(VariationSet[i].OuterXml);
        XmlNodeList CASInputParam = SingleVariationDom.GetElementsByTagName("CASInputParam");
        string Attr = null;
         ObjList.Clear();
        for (int j = 0; j < CASInputParam.Count; j++)
        {
            if (j == 0)
            {
                var NonTabularValueElement = SingleVariationDom.GetElementsByTagName("CASInputParam")[0];
                Attr = NonTabularValueElement.Attributes["MailParam"].Value;
            }
            else
            {
                var NonTabularValueElement = SingleVariationDom.GetElementsByTagName("CASInputParam")[j];
                string Attribut = NonTabularValueElement.Attributes["MailParam"].Value;
                ObjList.Add(Attribut);
            }
        }

        ObjParentDiction.Add(Attr, ObjList);

    }

リストオブジェクトObjListをクリアすると、すでにリストとして値を追加した辞書の値がクリアされます。

それを避けるために提案してください。

4

4 に答える 4

0
Create an instance of the list of object with
ObjList = new List() and ObjList.Clear() outside of the outerloop. 
then each time before entering the loop list of object will be cleared and 
after entering into the loop object will be repopulated again.

thanks.
于 2013-05-26T11:45:22.980 に答える