protected void btnWriteXML_Click(object sender, EventArgs e)
{
//Create document outline
const string strFileName = "D://WriteXMLExample.xml";
XmlTextWriter objXmlTW = new XmlTextWriter(strFileName, System.Text.Encoding.UTF8);
//Sets the indentation for the XML file
objXmlTW.Formatting = Formatting.Indented;
objXmlTW.Indentation = 4;
//Write XML Declatation
objXmlTW.WriteStartDocument();
//Write root element
objXmlTW.WriteStartElement("ct", "ContactDetails", "http://www.deltabis.com/Contact");
//Write attibute to the root element
objXmlTW.WriteAttributeString("updateDate", "20021201T14:00");
//Write contact child element node
objXmlTW.WriteStartElement("contact");
//Write empty title attribute
objXmlTW.WriteAttributeString("title", string.Empty);
//Write <name> element node
objXmlTW.WriteStartElement("name");
//Write <first> element node
objXmlTW.WriteElementString("first", "Steven");
//Write <middle> element node
objXmlTW.WriteElementString("middle", string.Empty);
//Write <last> element node
objXmlTW.WriteElementString("last", "Livingstone-Perez");
//Write Full end of <name> element node
objXmlTW.WriteFullEndElement();
//Write full end of <contact> element node
objXmlTW.WriteFullEndElement();
objXmlTW.WriteEndElement();
//end the XMLDocument
objXmlTW.WriteEndDocument();
//Write to the file and close;
objXmlTW.Flush();
objXmlTW.Close();
}