title: Why Error "System.String does not contain a method named 'AppendChild'"
body: <p>Why does this PowerShell Script not work:</p>
  
  
  
  <pre class="lang-psh prettyprint-override"><code>[xml]$xml = '&lt;products&gt;&lt;/products&gt;'
  
  $newproduct = $xml.CreateElement('product')
  $attr = $xml.CreateAttribute('code')
  $attr.Value = 'id1'
  $newproduct.Attributes.Append($attr)
  
  $products = $xml.products
  $products.AppendChild($newproduct)
  </code></pre>
  
  <p>Error is</p>
  
  <pre class="lang-none prettyprint-override"><code>Method invocation failed because [System.String] does not contain a method named 'AppendChild'.
  At line:1 char:1
  + $products.AppendChild($newproduct)
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : MethodNotFound
  </code></pre>
  
  <p>If I replace</p>
  
  <pre class="lang-psh prettyprint-override"><code>$products = $xml.products
  </code></pre>
  
  <p>by</p>
  
  <pre class="lang-psh prettyprint-override"><code>$products = $xml.SelectSingleNode('//products')
  </code></pre>
  
  <p>it will work, but I'd like to know why first syntax does not work because it is illogical for me. <code>$xml.products</code> should be a valid XML object and thus provide the method <code>AppendChild()</code>.</p>