This is what I have so far:
$XML = New-Object System.Xml.XmlDocument
$XML.PreserveWhitespace = $true
$XML.Load($path)
#change some node attributes
$XML.Save(
Please have a look at this answer to a question very similar to yours:
While there doesn't seem to be a way of preserving xml attribute formatting, you can define it yourself on the xml document by using the power of the XmlWriterSettings and XmlWriter classes.
You can specify it to have newlines between attributes like so:
$xwSettings = new-object System.Xml.XmlWriterSettings
$xwSettings.NewLineOnAttributes = $true
You then save the document using an XmlWriter together with these settings:
$xmlWriter = [Xml.XmlWriter]::Create("c:\temp\newlines.xml", $xwSettings)
$doc.Save($xmlWriter)
(Code is all from original answer. Kudos to vonPryz)
No XML parser in the world is going to tell you whether the attributes in a start tag are separated by spaces, newlines, or tabs. You aren't supposed to care.