Using XML in the .NET Framework "  Chapter 4 135 Figure 4.12  Simple XmlDocument Class using System; using System.Xml; namespace XmlDocumentProject { public class Class1 { public Class1() { } public static void Main() { XmlDocument myDoc = new XmlDocument(); XmlProcessingInstruction myProc = myDoc.CreateProcessingInstruction("xml", "version=\"1.0\""); myDoc.AppendChild(myProc); XmlElement myRoot = myDoc.CreateElement("rootNode"); myDoc.AppendChild(myRoot); XmlElement myElement = myDoc.CreateElement("firstSubElement"); myRoot.AppendChild(myElement); Console.WriteLine(myDoc.OuterXml); Console.Write("Press enter to finish..."); Console.ReadLine(); } } } The XmlDocumentProject is about as simple as it gets when working with XML data. In the first line of the Main method, an XmlDocument is created. Next, the program creates a processing instruction (the <? ?> tag) and adds it to the XmlDocument, although this is optional as the XmlDocument will still function www.syngress.com 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 135