【问题标题】:I want to change XML to Webconfig use Powershell我想使用 Powershell 将 XML 更改为 Webconfig
【发布时间】:2019-12-18 06:45:03
【问题描述】:

我想知道如何更改 XML 并保存

例如,这是 test1.xml

<AAA_KEY>
<Account_key> 123AA03 </Account_key>
    <KEY ID = "User10036">
        <key1> #1199DERE45  </key1>
        <key2> 455DSuyeias  </key2>
</AAA_KEY>

然后,我有一个 web.config

<www>
    <KEY ID = "User10036">
        <user> user1 </user>
        <key1> xxxxxx  </key1>
<www>

所以,我想知道如何读取 key1 ,复制到 web.config 并保存

例如

<www>
    <KEY ID = "User10036">
        <user> user1 </user>
        <key1> #1199DERE45  </key1>
<www>

【问题讨论】:

  • 您的语言标签是 javascript,但您的问题是 powershell。你能澄清一下吗?
  • 哦,对不起~我第一次使用Stackoverflow

标签: xml powershell web-config web-config-transform


【解决方案1】:

您的 xml 格式不正确...KEY 标记需要关闭。 我已将其编辑为我认为应该在下面的样子,如果不正确,请在您的问题中进行更改。

# read the files as xml objects
[xml]$test1 = Get-Content C:\temp\test1.xml
[xml]$webconfig = Get-Content C:\temp\web.config

# for testing, I'm just going to create the objects. you don't need to do this.
[xml]$test1 = @"
<AAA_KEY>
<Account_key> 123AA03 </Account_key>
    <KEY ID = "User10036">
        <key1> #1199DERE45  </key1>
        <key2> 455DSuyeias  </key2>
    </KEY>
</AAA_KEY>
"@
[xml]$webconfig = @"
<www>
    <KEY ID = "User10036">
        <user> user1 </user>
        <key1> xxxxxx  </key1>
    </KEY>
</www>
"@

# set the value
$webconfig.www.KEY.key1 = $test1.AAA_KEY.KEY.key1

# save web.config
$webconfig.Save("C:\temp\web.config")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 2017-11-11
    • 1970-01-01
    相关资源
    最近更新 更多