remove a duplicate element(with specific value) from xml using linq

crocket2308

New Member
If I have this xml\[code\]<?xml version="1.0" encoding="utf-8"?><super> <A value="http://stackoverflow.com/questions/11012101/1234"> <a1 xx="000" yy="dddddd" /> <a1 xx="111" yy="eeeeee" /> <a1 xx="222" yy="ffffff"/> </A></super>\[/code\]and I need to remove a1 element (that have xx=222) completely. why this won't happen using my code?? i realized that it will delete it only if it was placed the first element(i.e, if i want to delete a1 that have x=000 , it will delete it since its the first one), why is that??what wrong with the code ??\[code\]var employee = from emp in element.Elements("A") where (string)emp.Element("a1").Attribute("xx") == "222" select emp.Element("a1");foreach (var empployee_1 in employee){ empployee_1.Remove();}element.Save(@"TheLocation");\[/code\]thanks alot
 
Back
Top