我正在使用 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)
是否有一种方法可以在多行属性中保留换行符并在保存文件后保持缩进?