Mega Code Archive

 
Categories / C# / XML LINQ
 

XElement Save (XmlWriter) serializes this element to an XmlWriter

using System; using System.Text; using System.Xml; using System.IO; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass {     public static void Main()     {         StringBuilder sb = new StringBuilder();         XmlWriterSettings xws = new XmlWriterSettings();         xws.OmitXmlDeclaration = true;         using (XmlWriter xw = XmlWriter.Create(sb, xws))         {             XElement root = new XElement("Root",                 new XElement("Child", "child content")             );             root.Save(xw);         }         Console.WriteLine(sb.ToString());     } }