Mega Code Archive

 
Categories / C# / XML LINQ
 

XElement Save serializes this element to a file, optionally disabling formatting

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()     {         string str;         XElement root = XElement.Parse(@"<Root> <Child> Text </Child> </Root>");         root.Save("Root.xml", SaveOptions.DisableFormatting);         str = File.ReadAllText("Root.xml");         Console.WriteLine(str);         root.Save("Root.xml", SaveOptions.None);         str = File.ReadAllText("Root.xml");         Console.WriteLine(str);     } }