title: Duplicate xml document in powershell variable
body: <p>i'm struggling with duplicating an XmlDocument variable in powershell.<br>
  The script creates a new XmlDocument, adds declarations and namespaces and then generates some svg graphic nodes and saves everything as a .svg file.<br>
  So far everything works fine.  </p>
  
  <p>Now i want to create two slightly different .svg files (e.g. different colors) and therefore try to clone the XmlDocument variable into a new variable.  </p>
  
  <p>Simply assigning the variable like this:</p>
  
  <pre><code>[Xml]$exportSecondSVG = $exportSVG
  </code></pre>
  
  <p>will apparently just create a reference and all changes i make to the <strong>$exportSecondSVG</strong> document will also affect the original <strong>$exportSVG</strong> document.  </p>
  
  <p>So i tried this approach with <strong>$exportSVG.Clone()</strong> which also doesn't work - the <strong>$exportSecondSVG</strong> seems to be empty:</p>
  
  <pre><code># Create new xml File with header
  [xml]$exportSVG = New-Object System.Xml.XmlDocument
  
  # Add xml declaration header
  $decNode = $exportSVG.CreateXmlDeclaration("1.0","UTF-8",$null)
  $exportSVG.AppendChild($decNode) | Out-Null
  
  # Add namespaces to svg file
  $nsmgr = New-Object Xml.XmlNamespaceManager($exportSVG.NameTable)
  $nsmgr.AddNamespace('xlink','http://www.w3.org/1999/xlink');
  $nsmgr.AddNamespace('rdf',"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
  $nsmgr.AddNamespace('cc',"http://creativecommons.org/ns#");
  $nsmgr.AddNamespace('dc',"http://purl.org/dc/elements/1.1/");
  $nsmgr.AddNamespace('svg',"http://www.w3.org/2000/svg");
  
  # create root svg Node
  $rootSVG = $exportSVG.CreateNode("element","svg",$null)
  
  $exportSVG.AppendChild($rootSVG) | Out-Null
  
  # Clone original Document
  [Xml]$exportSecondSVG = $exportSVG.Clone()
  
  # DO SOME STUFF WITH $exportSVG 
  # DO DIFFERENT STUFF WITH $exportSecondSVG
  
  $exportSVG.Save("D:\File1.xml")
  $exportSecondSVG.Save("D:\File2.xml") # &lt;-- Empty File!
  </code></pre>
  
  <p>Is it possible to somehow clone / duplicate the XmlDocument variable?</p>
  
  <p>any help would be greatly appreciated!</p>