2 つの Arraylist と xml ファイルがあります。この xml ファイルを LINQ ステートメントでフィルター処理したいと考えています。
これが私のコードです:
ArrayList ListOfNPSGroups = MyClass.ActiveDirectoryManager.GetGroupsInOUByValue(); //all groups from the xml
ArrayList ActiveUserList = MyClass.ActiveDirectoryManager.GetGroupmemberList(DOMAIN, Username, ListOfNPSGroups); //only the user groups
XDocument x = XDocument.Load(Server.MapPath(@"~\App_Data\location.xml"));
IEnumerable<XElement> elements;
for (int i = 0; i < ActiveUserList.Count; i++)
{
elements = x.Descendants("plant").Where( xe => (string)xe.Attribute("group") == ActiveUserList[i].ToString());
foreach (XElement el in elements)
{
el.remove();
}
}
私のxml:
<plants>
<plant id="DB" display=".testDB.." group="NPS_DB" />
<plant id="EL" display=".testEL.." group="NPS_EL" />
<plant id="IN" display="..testIN." group="NPS_IN" />
<plant id="SB" display=".testSB.." group="NPS_SB" />
<plant id="BL" display=".testBL.." group="NPS_BL" />
<plant id="LS" display="..testLS.." group="NPS_LS" />
</plants>
例: ユーザーが、xml がこれに更新されたグループ nps_db および nps_el にのみ含まれている場合:
<plants>
<plant id="DB" display=".testDB.." group="NPS_DB" />
<plant id="EL" display=".testEL.." group="NPS_EL" />
</plants>
しかし、私のlinqステートメントは間違っていると思います:/