I am using XDocument in LINQ to edit (insert) and save xml document.
XDocument doc = XDocument.Load("c:\\sample.xml", LoadOptions.PreserveWhitespace);
doc.Save("c:\\sample.xml",SaveOptions.DisableFormatting)
sample.xml before doc.Save :
<ELEMENT ATTRIB1="attrib1" ATTRIB2="attrib2" >
value
</ELEMENT>
sample.xml after doc.Save
<ELEMENT ATTRIB1="attrib1" ATTRIB2="attrib2">
value
</ELEMENT>
As you can see, there is double space after ATTRIB1 and a single space after ATTRIB2 in the original document. But these spaces have been removed by linq when I call doc.save.
How can I preserve the whitespaces inside tag?