using System.Xml; XmlTextWriter writer = new XmlTextWriter("sample.xml", null); writer.WriteStartElement("book"); writer.WriteAttributeString("id", "001"); writer.WriteEndElement(); writer.Close();
using System.Xml; XmlTextWriter writer = new XmlTextWriter("sample.xml", null); writer.WriteStartElement("book"); writer.WriteAttributeString("id", "001"); writer.WriteAttributeString("name", "The Alchemist"); writer.WriteEndElement(); writer.Close();In this example, a file named sample.xml is created and an element named book is written with two attributes id=001 and name=The Alchemist. The package library for the System.Xml namespace is System.Xml.