【发布时间】:2017-03-15 16:57:39
【问题描述】:
我需要为换行符转义码设置一个 xml 值
<Variable>Foo 
 Bar</Variable>
我正在使用 get-content 创建一个 xml 对象并尝试使用以下方法分配变量
$qux = $("Foo 
 Bar")
$xml = [xml](Get-Content $xmlpath)
$xml.Variable = $qux
$xml.Save($tlpath)
$xml.Close
我尝试使用 & 代替 &,使用单引号和反斜杠,但我似乎无法阻止代码将 & 转换为 & 并吐出以下 xml
<Variable>Foo &#xA; Bar</Variable>
绕过 powershell 转换转义字符的最佳方法是什么?
【问题讨论】:
-
.Net XML 类saves \n as actual new lines inside text nodes。为什么需要它作为一个实体?
标签: xml powershell escaping