4

実際、私は 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 を作成することは可能ですか?

みんなありがとう!

4

1 に答える 1

6

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>
于 2012-10-18T17:41:46.087 に答える