title: How do I replace an XML root node with one of its child nodes?
body: <p>I want to remove some parent nodes from a XML document but keep the children. For example:</p>
  
  <p>I have this structure:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;ns:root xmlns:ns="ns"&gt;
      &lt;ns:node1&gt;
          &lt;ns:node2&gt;
              &lt;ns:node3&gt;
              &lt;/ns:node3&gt;
              &lt;ns:node4&gt;
              &lt;/ns:node4&gt;
          &lt;/ns:node2&gt;
      &lt;/ns:node1&gt;
  &lt;/ns:root&gt;
  </code></pre>
  
  <p>and want to get this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;ns:node2 xmlns:ns="ns"&gt;   &lt;!-- new root --&gt;
      &lt;ns:node3&gt;
      &lt;/ns:node3&gt;
      &lt;ns:node4&gt;
      &lt;/ns:node4&gt;
  &lt;/ns:node2&gt;
  </code></pre>
  
  <p>My current script looks like this:</p>
  
  <pre><code># Get the content as xml
  $xml = [xml] (gc c:\test.xml)
  
  
  # Grab the namespace
  $namespaceMgr = New-Object System.Xml.XmlNamespaceManager $xml.NameTable
  $namespace = $xml.DocumentElement.NamespaceURI
  $namespaceMgr.AddNamespace("ns", $namespace)
  
  # Select node2
  $xml.SelectSingleNode('/ns:root/ns:node1/ns:node2', $namespaceMgr) 
  
  # How to save it now as a new valid xml file?
  </code></pre>