XMLDocument.Save adds return carriages to XML when elements are blank XMLDocument.Save adds return carriages to XML when elements are blank xml xml

XMLDocument.Save adds return carriages to XML when elements are blank


This fixed it for me...

XmlDocument xmlDoc = new XmlDocument();xmlDoc.Load(@"C:\test.xml");//Save the xml and then cleanupXmlWriterSettings settings = new XmlWriterSettings { Indent = true };XmlWriter writer = XmlWriter.Create(@"C:\test.xml", settings);xmlDoc.Save(writer);


Probably too late, but I referred to the solution given by Arvo Bowen. Arvo's solution is in C#, I wrote the same in Powershell Syntax

# $dest_file is the path to the destination file$xml_dest = [XML] (Get-Content $dest_file)##   Operations done on $xml_dest#$settings = new-object System.Xml.XmlWriterSettings$settings.CloseOutput = $true$settings.Indent = $true$writer = [System.Xml.XmlWriter]::Create($dest_file, $settings)$xml_dest.Save($writer)$writer.Close()

It solved my two problems: