I want to read in an XML file and modify an element then save it back to the file. What is the best way to do this while preserving the format and also keep matching Line terminator (CRLF vs LF)?
Here is what I have but it doesn't do that:
$xml = [xml]([System.IO.File]::ReadAllText($fileName))
$xml.PreserveWhitespace = $true
# Change some element
$xml.Save($fileName)
The problem is that extra new lines (aka empty lines in the xml) are removed and after I have mixed LF and CRLF.