Mega Code Archive

 
Categories / C# / XML LINQ
 

XElement Save (TextWriter, SaveOptions) serializes this element to a TextWriter

using System; using System.IO; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){         XElement root = XElement.Parse(@"<Root> <Child> Text </Child> </Root>");                  using (StringWriter sw = new StringWriter())         {             root.Save(sw, SaveOptions.DisableFormatting);             Console.WriteLine(sw.ToString());         }                  using (StringWriter sw = new StringWriter())         {             root.Save(sw, SaveOptions.None);             Console.WriteLine(sw.ToString());         }     } }