title: XmlNode RemoveAll() nullifies reference of nodes held by other variables
body: <p>i am trying to remove all child nodes from root apart from the one that is needed to be present and here is what i wrote</p>
  
  <pre><code>                XmlNode root = XmlTemplate.DocumentElement;
  
                  string targetPrefix = root.Prefix;
                  var xmlNamespaceManager = new XmlNamespaceManager(XmlTemplate.NameTable);
                  xmlNamespaceManager.AddNamespace(root.Prefix, root.NamespaceURI);
                  XmlNodeList nodeList = null;
                  if (!String.IsNullOrEmpty(targetPrefix))
                  {
                      nodeList = root.SelectNodes("descendant::" + targetPrefix + ":fields", xmlNamespaceManager);
                  }
                  else
                  {
                      nodeList = root.SelectNodes("descendant::fields");
                  }
  </code></pre>
  
  <p>As expected I am able to get the required node in nodeList. i can the node in debug mode. Confusion starts when below code statements run</p>
  
  <pre><code>root.RemoveAll();
  root.AppendChild(nodeList[0]);
  </code></pre>
  
  <p>as per my understanding the child node is still referenced in the nodeList hence object would have not got garbage collected but after root.RemoveAll() executes nodeList becomes empty.</p>
  
  <p><code>root.innexText ="";</code> also does same</p>
  
  <p>is there anything different with XML methods? which concept have i misunderstood...</p>