C# 如何为xml文件中的filter to arraylist值获取正确的linq语句?
我有两个ArrayList和一个xml文件。我想用LINQ语句过滤这个xml文件 这是我的密码:C# 如何为xml文件中的filter to arraylist值获取正确的linq语句?,c#,asp.net,xml,linq,arraylist,C#,Asp.net,Xml,Linq,Arraylist,我有两个ArrayList和一个xml文件。我想用LINQ语句过滤这个xml文件 这是我的密码: ArrayList ListOfNPSGroups = MyClass.ActiveDirectoryManager.GetGroupsInOUByValue(); //all groups from the xml ArrayList ActiveUserList = MyClass.ActiveDirectoryManager.GetGroupmemberList(DOMAIN, Userna
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();
}
}
arraylistlistofnpsgroups=MyClass.ActiveDirectoryManager.GetGroupsInOUByValue()//xml中的所有组
ArrayList ActiveUserList=MyClass.ActiveDirectoryManager.GetGroupmemberList(域、用户名、ListOfNPSGroups)//只有用户组
XDocument x=XDocument.Load(Server.MapPath(@“~\App\u Data\location.xml”);
可数元素;
for(int i=0;i(string)xe.Attribute(“group”)==ActiveUserList[i].ToString());
foreach(元素中的元素el)
{
el.移除();
}
}
我的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>
例如:如果我的用户仅在组nps_db和nps_el中,我希望我的xml更新为:
<plants>
<plant id="DB" display=".testDB.." group="NPS_DB" />
<plant id="EL" display=".testEL.." group="NPS_EL" />
</plants>
但我认为我的linq声明是错误的:/你在找这个吗
List<string> list = new List<string>{"NPS_DB", "NPS_IN"};
string 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>";
var xDoc = XDocument.Parse(xml);
xDoc.Root.Descendants()
.Where(e => !list.Contains((string)e.Attribute("group")))
.ToList()
.ForEach(s => s.Remove());
List List=新列表{“NPS_DB”,“NPS_IN”};
字符串xml=@“
";
var xDoc=XDocument.Parse(xml);
xDoc.Root.substands()的
.Where(e=>!list.Contains((字符串)e.Attribute(“组”))
托利斯先生()
.ForEach(s=>s.Remove());
看起来您甚至还没有尝试您的linq语句
?我想是的,因为你说了这个我认为我的linq声明是错误的
我可以将这个新的xDoc绑定到我的DropDownList吗?我尝试这样做:drpLogLocation.DataSource=x;drpLogLocation.DataBind();x是我的x文档。。