XML C# Book

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:




2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test


2010-12-17T00:00:00-08:00
test