// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Xml; class MainClass { public static void Main(string[] args) { XmlDocument doc = new XmlDocument(); XmlNode root = doc.CreateElement("all"); doc.AppendChild(root); for(int i = 0; i < 5; i++) { XmlNode elm = doc.CreateElement("one"); elm.AppendChild(doc.CreateTextNode("Element #" + (i + 1))); root.AppendChild(elm); } doc.InsertBefore(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"), doc.DocumentElement); doc.Save(@"C:\test2.xml"); } }