I want to remove a node from a xml file using value of an element
Here is my xml
<Employee>
<User>
<ID>1</ID>
<Username>John</Username>
<Lastname>Smith</Lastname>
</User>
<User>
<ID>2</ID>
<Username>jerry</Username>
<Lastname>wilson</Lastname>
</User>
</Employee>
And here is my code behind
XDocument doc = XDocument.Load(Server.MapPath(@"~/User.xml"));
doc.Elements("User")
.Elements("ID")
.Where(l => l.Value == textbox1.text)
.Select(x => x.Parent)
.Remove();
i want to remove the <user> node whose <id> is entered in textbox
but its not working.
Can you help me?
Add
doc.Rootproperty ordoc.Descendants("User")to return filtered collection of the descendant elements :1.
2.