I have the following XML:
<?xml version="1.0" encoding="utf-8"?>
<foo>
<bar key="baz" value='
{
"a": {
"b": {
"c": "info"
}
}
}
' />
</foo>
I want to load this file in ps, do some work with it then save it back. At the moment, what I do is the following:
$xmlDocument = [System.Xml.XmlDocument]::new()
$xmlDocument.PreserveWhitespace = $true
$xmlDocument.Load('.\my.xml')
$settings = [System.Xml.XmlWriterSettings]@{
Encoding = [System.Text.UTF8Encoding]::new($true)
Indent = $true
}
$xmlWriter = [System.Xml.XmlWriter]::Create('.\my.xml', $settings)
try {
$xmlDocument.Save($xmlWriter)
}
finally {
$xmlWriter.Dispose()
}
And I get the following output.
<?xml version="1.0" encoding="utf-8"?>
<foo>
<bar key="baz" value="
{
 "a": {
 "b": {
 "c": "info"
 }
 }
}
" />
</foo>
Is it possible to write this file without escaping the values?