实际上,我对xtd-transform了解不多。我需要在我的xdt文件中:
<add key="EndpointName" value="SomeValue" xdt:Transform="SetAttributes(value)" xdt:Locator="Match(key)" />我在powershell中做的例行工作:
$cache.SetAttribute("key","EndpointName")
$cache.SetAttribute("value","SomeValue")
$cache.SetAttribute("xdt:Transform","SetAttributes(value)")
$cache.SetAttribute("xdt:Locator","Match(key)")这就是我所拥有的。不符合我的观点:
<add key="EndpointName" value="Email" Transform="SetAttributes(value)" Locator="Match(key)" />那么是否可以使用powershell脚本创建xdt:attribute呢?
谢谢你们!
发布于 2012-10-19 01:41:46
当涉及到XML名称空间时,您需要使用XmlNamespaceManager,例如:
$xdt = 'http://schemas.microsoft.com/XML-Document-Transform'
$xml = [xml]"<doc xmlns:xdt='$xdt'><add key='foo' value='foo' xdt:Transform='foo' xdt:Locator='foo'/></doc>"
$nsmgr = new-object Xml.XmlNamespaceManager $xml.NameTable
$nsmgr.AddNamespace("xdt", $xdt)
$xml.doc.add.SetAttribute('Transform', $xdt, 'SetAttribute(value)') > $null结果如下:
<doc xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<add key="foo" value="foo" xdt:Transform="SetAttribute(value)" xdt:Locator="foo" />
</doc>https://stackoverflow.com/questions/12954933
复制相似问题