title: Load XML containing custom namespace
body: <p>Using PowerShell scripts to dynamically append XML tags.
  In this case trying to add a custom ElasticSearch target for NLog (from <a href="https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch" rel="nofollow">here</a>).</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$source = '&lt;target name="elastic" xsi:type="BufferingWrapper"&gt;  &lt;/target&gt;'
  </code></pre>
  
  <p>When converting <code>$source</code> to XML using</p>
  
  <pre class="lang-bsh prettyprint-override"><code>[xml]$source
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$xml = New-Object -TypeName System.Xml.XmlDocument
  $xml.LoadXml($source)
  </code></pre>
  
  <p>I get the following error</p>
  
  <blockquote>
    <p>Cannot convert value "&lt;targetname="elastic" xsi:type="BufferingWrapper"&gt;  &lt;/target&gt;" to type "System.Xml.XmlDocument". Error: "'xsi' is an undeclared prefix."</p>
  </blockquote>
  
  <p>Any suggestions?</p>
  
  <p><strong>Almost, but not quite there:</strong></p>
  
  <p>I can use <code>ConvertTo-Xml $source -as Document</code> but the result doesn't use the <code>&lt;target&gt;</code> tag, it uses <code>&lt;Object&gt;</code>, which doesn't work in this case.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Objects&gt;
    &lt;Object Type="System.String"&gt;&amp;lt;target name="elastic" xsi:type="BufferingWrapper"
  &lt;Objects&gt;
  </code></pre>