使用PowerShell脚本动态添加XML标记。 在这种情况下,试图为NLog添加自定义ElasticSearch目标(从here)。加载包含自定义名称空间的XML
$source = '<target name="elastic" xsi:type="BufferingWrapper"> </target>'
当使用
[xml]$source
或
$xml = New-Object -TypeName System.Xml.XmlDocument
$xml.LoadXml($source)
我收到以下错误
Cannot convert value "<targetname="elastic" xsi:type="BufferingWrapper"> </target>" to type "System.Xml.XmlDocument". Error: "'xsi' is an undeclared prefix."
任何建议转换$source
到XML?
差不多了,但也不能令人信服:
我可以使用ConvertTo-Xml $source -as Document
但结果不使用<target>
标签,它使用<Object>
,这并不在这种情况下工作。
<?xml version="1.0" encoding="utf-8"?>
<Objects>
<Object Type="System.String"><target name="elastic" xsi:type="BufferingWrapper"
<Objects>