Using PowerShell scripts to dynamically append XML tags. In this case trying to add a custom ElasticSearch target for NLog (from here).
$source = '<target name="elastic" xsi:type="BufferingWrapper"> </target>'
When converting $source to XML using
[xml]$source
or
$xml = New-Object -TypeName System.Xml.XmlDocument
$xml.LoadXml($source)
I get the following error
Cannot convert value "<targetname="elastic" xsi:type="BufferingWrapper"> </target>" to type "System.Xml.XmlDocument". Error: "'xsi' is an undeclared prefix."
Any suggestions?
Almost, but not quite there:
I can use ConvertTo-Xml $source -as Document but the result doesn't use the <target> tag, it uses <Object>, which doesn't work in this case.
<?xml version="1.0" encoding="utf-8"?>
<Objects>
<Object Type="System.String"><target name="elastic" xsi:type="BufferingWrapper"
<Objects>