usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Xml;namespacecreate an XML document with attributes {classProgram {Static voidMain (string[] args) {XmlDocument doc=NewXmlDocument (); XmlDeclaration Dec= Doc. Createxmldeclaration ("1.0","Utf-8",NULL); Doc. AppendChild (DEC); XmlElement Order= Doc. CreateElement ("Order"); Doc. AppendChild (order); XmlElement CustomerName= Doc. CreateElement ("CustomerName"); Customername.innertext="I 'm hungry."; Order. AppendChild (CustomerName); XmlElement Items= Doc. CreateElement ("Items"); Order. AppendChild (items); XmlElement orderItem1= Doc. CreateElement ("OrderItem"); Orderitem1.setattribute ("Name","Fried Powder Dry"); Orderitem1.setattribute ("Count","2"); Items. AppendChild (ORDERITEM1); Doc. Save ("Order.xml"); Console.WriteLine ("saved successfully"); Console.readkey (); } }}
To create an XML document with attributes