protected void Page_Load( object sender, EventArgs e)
{
string xmlPath = Server.MapPath( " ~/Employee.xml " );
XmlWriterSettings setting = new XmlWriterSettings();
setting.Indent = true ;
setting.IndentChars = " \t " ;
using (XmlWriter writer = XmlWriter.Create(xmlPath,setting))
{
writer.WriteStartDocument( false );
writer.WriteComment( " This XML file represents the details of an employee " );
writer.WriteStartElement( " employees " );
writer.WriteStartElement( " employee " );
writer.WriteAttributeString( " id " , " 1 " );
writer.WriteStartElement( " name " );
writer.WriteElementString( " firstName " , " Nancy " );
writer.WriteElementString( " lastName " , " lastName " );
writer.WriteEndElement();
writer.WriteElementString( " city " , " Seattle " );
writer.WriteElementString( " state " , " WA " );
writer.WriteElementString( " zipCode " , " 98122 " );
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
lblResult.Text = " File is written successfully! " ;
}
}