首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用powershell的xdt

使用powershell的xdt
EN

Stack Overflow用户
提问于 2012-10-18 20:41:28
回答 1查看 892关注 0票数 4

实际上,我对xtd-transform了解不多。我需要在我的xdt文件中:

代码语言:javascript
复制
<add key="EndpointName" value="SomeValue" xdt:Transform="SetAttributes(value)" xdt:Locator="Match(key)" />

我在powershell中做的例行工作:

代码语言:javascript
复制
$cache.SetAttribute("key","EndpointName")
$cache.SetAttribute("value","SomeValue")
$cache.SetAttribute("xdt:Transform","SetAttributes(value)")
$cache.SetAttribute("xdt:Locator","Match(key)")

这就是我所拥有的。不符合我的观点:

代码语言:javascript
复制
<add key="EndpointName" value="Email" Transform="SetAttributes(value)" Locator="Match(key)" />

那么是否可以使用powershell脚本创建xdt:attribute呢?

谢谢你们!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-19 01:41:46

当涉及到XML名称空间时,您需要使用XmlNamespaceManager,例如:

代码语言:javascript
复制
$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

结果如下:

代码语言:javascript
复制
<doc xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <add key="foo" value="foo" xdt:Transform="SetAttribute(value)" xdt:Locator="foo" />
</doc>
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12954933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档