I have a document on which I'm replacing the inner XML of some node:
var xmlReplacement = File.ReadAllText(path); // this xml is well formatted with indentations itself, but not indented at the correct level for the document it's about to be inserted into
var document = new XmlDocument();
document.PreserveWhitespace = true;
document.Load(path);
// replace inner xml of ContainingNode
var node = document.SelectSingleNode("//ContainingNode");
node.InnerXml = xmlReplacement;
// write back to the output file
using (var writer = new XmlTextWriter(path, null))
{
writer.Formatting = Formatting.Indented;
document.WriteTo(writer);
}
I end up getting the new inner xml non-indented (all the way to the left) and the close node on the same line as the close of my replacement xml's node.
How can I get this right?