Lets imagine we have task:
Select all nodes <Test> from XML file using Xpath and delete them.
No problem:

XmlNodeList nodeList = xml.SelectNodes("//Test");  
foreach (XmlNode node in nodeList)  
{
      node.ParentNode.RemoveChild(node);
}

What can be wrong with this code? Nevertheless lets test it.

Create a simple XML Document test.xml:

<?xml version="1.0"?>  
<Tests>  
  <Test TestId="0001" TestType="CMD">
    <Name>Convert number to string</Name>
    <CommandLine>Examp1.EXE</CommandLine>
    <Input>1</Input>
    <Output>One</Output>
  </Test>
  <Test TestId="0002" TestType="CMD">
    <Name>Find succeeding characters</Name>
    <CommandLine>Examp2.EXE</CommandLine>
    <Input>abc</Input>
    <Output>def</Output>
    <Test TestId="0009" TestType="CMD">
      <Test TestId="0012" TestType="CMD">
        <Name>Find succeeding characters</Name>
        <CommandLine>Examp2.EXE</CommandLine>
        <Input>abc</Input>
        <Output>def</Output>
      </Test>
      <Name>Find succeeding characters</Name>
      <CommandLine>Examp2.EXE</CommandLine>
      <Input>abc</Input>
      <Output>def</Output>
    </Test>
  </Test>
  <Node>
  </Node>
  <Test TestId="0003" TestType="GUI">
    <Name>Convert multiple numbers to strings</Name>
    <CommandLine>Examp2.EXE /Verbose</CommandLine>
    <Input>123</Input>
    <Output>One Two Three</Output>
  </Test>
  <Test TestId="0004" TestType="GUI">
    <Name>Find correlated key</Name>
    <CommandLine>Examp3.EXE</CommandLine>
    <Input>a1</Input>
    <Output>b1</Output>
  </Test>
  <Test TestId="0005" TestType="GUI">
    <Name>Count characters</Name>
    <CommandLine>FinalExamp.EXE</CommandLine>
    <Input>This is a test</Input>
    <Output>14</Output>
  </Test>
  <Test TestId="0006" TestType="GUI">
    <Name>Another Test</Name>
    <CommandLine>Examp2.EXE</CommandLine>
    <Input>Test Input</Input>
    <Output>10</Output>
  </Test>
</Tests>  

Full code of our simple test app:

static void Main(string[] args)  
{
      XmlDocument xml = new XmlDocument();
      xml.Load("C:/temp/test.xml");
      XmlNodeList nodeList = xml.SelectNodes("//Test");

      foreach (XmlNode node in nodeList)
      {
            node.ParentNode.RemoveChild(node);
      }
      xml.Save("C:/temp/result.xml");
}

Now run app and open result file result.xml:

<?xml version="1.0"?>  
<Tests>  
  <Node>
  </Node>
  <Test TestId="0003" TestType="GUI">
    <Name>Convert multiple numbers to strings</Name>
    <CommandLine>Examp2.EXE /Verbose</CommandLine>
    <Input>123</Input>
    <Output>One Two Three</Output>
  </Test>
  <Test TestId="0004" TestType="GUI">
    <Name>Find correlated key</Name>
    <CommandLine>Examp3.EXE</CommandLine>
    <Input>a1</Input>
    <Output>b1</Output>
  </Test>
  <Test TestId="0005" TestType="GUI">
    <Name>Count characters</Name>
    <CommandLine>FinalExamp.EXE</CommandLine>
    <Input>This is a test</Input>
    <Output>14</Output>
  </Test>
  <Test TestId="0006" TestType="GUI">
    <Name>Another Test</Name>
    <CommandLine>Examp2.EXE</CommandLine>
    <Input>Test Input</Input>
    <Output>10</Output>
  </Test>
</Tests>  

Not all Test nodes deleted! But how we can remove them correctly?

Very simple, just change foreach to regular for loop:

for (int i = 0; i < nodeList.Count; i++)  
{
    nodeList[i].ParentNode.RemoveChild(nodeList[i]);
}

Result:

<?xml version="1.0"?>  
<?xml version="1.0"?>  
<Tests>  
  <Node>
  </Node>
</Tests>  

Why?

Because you are not allowed to change the collection within foreach loop. MSDN says:

The foreach statement is used to iterate through the collection to get the information that you want, but can not be used to add or remove items from the source collection to avoid unpredictable side effects. If you need to add or remove items from the source collection, use a for loop. Read more about foreach on MSDN