Save XmlDocument without carriage returns and spaces


   
//
//Save XmlDocument without carriage returns and spaces
//
private void SaveCompatibleXmlDocument(XmlDocument xDoc, string filePath){
   XmlWriterSettings wSettings = new XmlWriterSettings();
   wSettings.Indent = true;
   wSettings.IndentChars = String.Empty;
   wSettings.NewLineChars = "\n";
   wSettings.NewLineHandling = NewLineHandling.Replace;
   wSettings.Encoding = System.Text.Encoding.UTF8;
   XmlWriter xWriter = XmlWriter.Create(filePath, wSettings);
   try{
     xDoc.Save(xWriter);
   }finally{
     xWriter.Close();
   }
}

You can view this article online at:
http://www.kiranreddys.com/knowledgebase/index.php/article/save-xmldocument-without-carriage-returns-and-spaces