I have an XML document from which I want to remove white spaces and carriage returns. How can I get the modified XML using C#.
To remove white spaces between the tags:
# Regex regex = new Regex(@">\s*<");
# string cleanedXml = regex.Replace(dirtyXml, "><");
Source and other usefull info here
Set the preserveWhitespace flag to false:
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = false;
doc.Load("foo.xml");
// doc.InnerXml contains no spaces or returns