Using XML in the .NET Framework "  Chapter 4 141 Figure 4.14  Continued XmlElement mySecondElement = myDoc.CreateElement("subSubElement"); XmlAttribute myAttribute = myDoc.CreateAttribute("attribute"); myAttribute.Value = "this is my attribute value"; myElement.SetAttributeNode(myAttribute); myElement.SetAttribute("attribute2", "this is my second attribute value"); myElement.AppendChild(mySecondElement); Console.WriteLine(myDoc.OuterXml); Console.Write("Press enter to finish..."); Console.ReadLine(); } } } The first step in the code is to create an XmlDocument and add a root element to it. Next, two additional XmlElements are created, subElement and subSubElement. Next, a new attribute is created from the XmlDocument object and its value is set to this is my attribute value. Next, the attribute that was just created is added using the SetAttributeNode method of the XmlElement class, and another attribute is added using the SetAttribute method. Finally, the mySecondElement object is added as a child to the myElement object, and the entire documents XML is written to the console: <rootElement> <subElement attribute="this is my attribute value" attribute2="this is my second attribute value"> <subSubElement /> </subElement> </rootElement> www.syngress.com 155_xml_net_pd_C04.qk  3/6/02  1:57 PM  Page 141