Improving iterative manipulation on XML elements In this reply, there's an example of how to remove a node from a XML structure.

XElement doc = XElement.Load("test.xml");
doc.XPathSelectElement("//beep").Remove();


Suppose now that we wish to remove not a single node (specifying it by the string value) but a set of nodes (specifying them by an array of strings).

One way to resolve it is to loop through the array and execute the removal for each string element. However, I'd like to know if someone can suggest a neater approach.

IEnumerable&lt;String&gt; beeps = new[] { "//beep" };
XElement doc = XElement.Load("test.xml");
foreach(String beep in beeps)
  doc.XPathSelectElement(beep).Remove();
Let us say you have a node like this which is having two nodes , node1 and node 2, you need to specify xpath using "|" seperated . here is an example .

XPathSelectElement should be replaced with XPathSelectElements.

&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;customer&gt;
  &lt;node1&gt;
  &lt;/node1&gt;
  &lt;node2&gt;
  &lt;/node2&gt;
&lt;/customer&gt;




//all you need sepcify is a "|" to work it out.
doc.XPathSelectElements("//node1 | //node2").Remove();