/// <summary>
/// Generates XML string from an XElement
/// summary>
/// <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
xml.WriteTo(xw);
}
return sb.ToString();
}
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.
3 comments:
Thanks for this - it really helped a lot!
yοu аre іn reality a еxcеllent webmaster.
The wеb sіte loading pace is incrediblе.
It sοrt of feels that you are doing any unique trick.
Also, The contents are maѕterwork. you've performed a fantastic process on this matter!
Visit my website ipad3
Hello, Nеat pоst. There is а problem ωіth your site in web explorеr, may check this?
IE nonethеless is the market chіef аnd a goοd pοrtion of otheг people will
leave out your magnіficent writing becаuse of this рroblem.
Here is my web blog ... billigste ipad
Post a Comment