tags:

views:

451

answers:

2

I have an xml document from which i want to remove white spaces and cartridge returns. how can i get the modified xml using c#

+1  A: 

To remove white spaces between the tags:

# Regex regex = new Regex(@">\s*<");  
# string cleanedXml = regex.Replace(dirtyXml, "><");

Source and other usefull info here

a b
+3  A: 

Set the preserveWhitespace flag to false:

XmlDocument doc = new XmlDocument();
doc.preserveWhitespace = false;
doc.load("foo.xml");
// doc.InnerXml contains no spaces or returns
Coded Signal