I am giving you a generic solution
Create a class
**
public class Person
{
public string Email { get; set; }
public string DOB { get; set; }
public string City { get; set; }
}
**
After that write this method in your any class library like that
Public Class Utilities
{
public static XmlElement Serialize(object transformObject)
{
XmlElement serializedElement = null;
try
{
MemoryStream memStream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(transformObject.GetType());
serializer.Serialize(memStream, transformObject);
memStream.Position = 0;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(memStream);
serializedElement = xmlDoc.DocumentElement;
}
catch (Exception SerializeException)
{
}
return serializedElement;
}
}
Now write this main function at your page , where you want make this task
private void MainMethod()
{
Collection<Person> mPersons = new Collection<Person>();
//Fill your collection object mPersons with data
// I am giving here example for demo
Person sPerson = new Person();
sPerson.City = "City 1";
sPerson.DOB = DateTime.Now.ToString("YYYY-MM-DD HH:MM:SS"); //just for example
sPerson.Email = "[email protected]";
mPersons.Add(sPerson);
//add another class object
sPerson = new Person();
sPerson.City = "City 2";
sPerson.DOB = DateTime.Now.ToString("YYYY-MM-DD HH:MM:SS"); //just for example
sPerson.Email = "[email protected]";
mPersons.Add(sPerson);
XmlElement xE = (XmlElement)Utilities.Serialize(mPersons);
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xE.OuterXml.ToString());
xDoc.Save(Server.MapPath("myFile.xml"));//give your file path name may be in your web application folder
}
Try this, if you have class object or dataset