title: Powershell System.Xml.XmlElement but I use System.Xml.XmlDocument?
body: <p>I keep getting the following exception in my PowerShell script:</p>
  
  <blockquote>
    <p>Method invocation failed because [System.Xml.XmlElement] does not
    contain a method named CreateElement'.</p>
  </blockquote>
  
  <p>But as far as I know I am using <code>System.Xml.XmlDocument</code>?
  <a href="https://msdn.microsoft.com/en-us/library/fw1ys7w6(v=vs.110).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/fw1ys7w6(v=vs.110).aspx</a></p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>$file = "file.xml"
  $xmlDoc = [System.Xml.XmlDocument](Get-Content $file)
  
  if ($xmlDoc) {
      $xmlDoc.layout.nodes.SetAttribute("environment", "develop"); #this works
  
      $newNode = $xmlDoc.layout.nodes.CreateElement("Node")
      $newNode.SetAttribute("name", "Hello world")
  
      $xmlDoc.AppendChild($newNode)
  
      $xmlDoc.Save($systemConfigFile)
  }
  </code></pre>
  
  <p>The XML file is before I launch this script:</p>
  
  <pre><code>&lt;layout&gt;
      &lt;nodes enviroment="[uknown]"&gt;
      &lt;/nodes&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>I expect the outcome te become:</p>
  
  <pre><code>&lt;layout&gt;
      &lt;nodes enviroment="develop"&gt;
          &lt;node name="Hello world" /&gt;
      &lt;/nodes&gt;
  &lt;/layout&gt;
  </code></pre>