Mega Code Archive

 
Categories / C# / XML LINQ
 

Writes this node to an XmlWriter

using System; using System.Text; using System.IO; using System.Xml; 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;         xws.Indent = true;         using (XmlWriter xw = XmlWriter.Create(sb, xws))         {             xw.WriteStartElement("Root");             XElement child1 = new XElement("A",                 new XElement("GrandChild", "some content")             );             child1.WriteTo(xw);             XElement child2 = new XElement("AnotherChild",                 new XElement("GrandChild", "different content")             );             child2.WriteTo(xw);             xw.WriteEndElement();         }         Console.WriteLine(sb.ToString());     } }