using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Text; using System.IO; class Program { static void Main() { using (XmlWriter w = XmlWriter.Create("foo.xml")) { w.WriteStartElement("log"); for (int i = 0; i < 10; i++) { XElement e = new XElement("logentry", new XAttribute("id", i), new XElement("date", DateTime.Today.AddDays(-1)), new XElement("source", "test")); e.WriteTo(w); } w.WriteEndElement(); } } } The content of foo.xml: