/// Generates XML string from an XElement
/// <param name="xml">XElement source</param>
public string GetXmlString(XElement xml)
// could also be any other stream
StringBuilder sb = new StringBuilder();
// Initialize a new writer settings
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = true;
using (XmlWriter xw = XmlWriter.Create(sb, xws))
// the actual writing takes place
It is important to know that the XElement already supports ToString which generates the same results as this code, but when you want to get something else, this could be a good start.
See further information in MSDN.