XML namepace has XmlWriter class to write to XML file.
Code in C#:
using System.XML; //Add this namespace to use XmlWriter and XmlReader classes
StringBuilder sb = new StringBuilder();
XmlWriter xwrite = XmlWriter.Create("c:\\sample.xml"); // here you can provide the path for the xml file.
//If you want to write to a string instead of file.Replace the above line with the following line.
//XmlWriter xwrite = XmlWriter.Create(sb);
writer.WriteStartDocument(true);
writer.WriteStartElement("USERNAME");writer.WriteString("Admin");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();