考虑以下PowerShell代码片段:
$xmldoc = New-Object xml
$xmldoc.PreserveWhitespace = $true
# no error
$sigws1 = $xmldoc.CreateSignificantWhitespace(" ")
# error
$sigws2 = $xmldoc.CreateSignificantWhitespace("\n")
Exception calling "CreateSignificantWhitespace" with "1" argument(s): "The string for white space contains an invalid character."
At line:1 char:1
+ $sigws2 = $xml.CreateSignificantWhitespace("\n")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
根据当前的微软文档,例如参见https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument.createsignificantwhitespace?view=net-5.0,以下是有效的空格“字符”:
 and 	
在参数字符串中包含换行符/换行符的正确方法是什么?
发布于 2021-06-24 19:29:24
PowerShell使用反引号`
作为转义字符:
$sigws1 = $xmldoc.CreateSignificantWhitespace("`n")
请参见概念性about_Special_Characters帮助主题。
https://stackoverflow.com/questions/68114864
复制相似问题