You can use this extension method :
public static void RemoveEmptyElementsAndWhiteSpaces(this XDocument document)
{
if(null == document)
throw new ArgumentNullException("document");
document.Descendants()
.Where(e => e.IsEmpty || string.IsNullOrWhiteSpace(e.Value))
.Remove();
}
Edit : if you are using the XmlDocument class, maybe you can set the PreserveWhiteSpace property to false ?