相关疑难解决方法(0)

在 Powershell 中使用 xml.document 保留多行属性和缩进

我正在使用 Powershell 来读取和修改 web.config 文件,所有操作都成功执行,但在保存文件时我丢失了缩进和多行属性中的新中断。以下是编辑前 web.config 文件的样子:

<maintenance isSet="false" startDate="2012-03-07T00:00:00" endDate="2012-03-07T23:59:59">
    <allowedIPAddresses>
        <add name="Johns Machine" address = "xx.xx.xxx.xx" />
        <add name="Marys Machine" address = "xx.xx.xxx.xx" />
    </allowedIPAddresses>
Run Code Online (Sandbox Code Playgroud)

以下是编辑 xml 的 Powershell 代码:

<maintenance isSet="false" startDate="2012-03-07T00:00:00" endDate="2012-03-07T23:59:59">
    <allowedIPAddresses>
        <add name="Johns Machine" address = "xx.xx.xxx.xx" />
        <add name="Marys Machine" address = "xx.xx.xxx.xx" />
    </allowedIPAddresses>
Run Code Online (Sandbox Code Playgroud)

这是脚本运行后的文件

<maintenance isSet="false" startDate="2012-03-07T00:00:00" endDate="2012-03-07T23:59:59">
<allowedIPAddresses><add name="Johns Machine" address="xx.xx.xxx.xx" /><add name="Marys Machine" address="xx.xx.xxx.xx" /></allowedIPAddresses>
Run Code Online (Sandbox Code Playgroud)

是否有一种方法可以在多行属性中保留换行符并在保存文件后保持缩进?

.net xml powershell web-config

4
推荐指数
1
解决办法
3190
查看次数

标签 统计

.net ×1

powershell ×1

web-config ×1

xml ×1