// 1. ———————————————————————-
[XmlRoot(“Person”)]
public class Person
{
[XmlElement(“Name”)]
public string Name { get; set; }

[XmlElement(“LastName”)]
public string LastName { get; set; }

[XmlElement(“Age”)]
public int Age { get; set; }

public string GetSerializedXml()
{
string xmlString = String.Empty;
using (StringWriter outStream = new StringWriter())
{
XmlSerializer s = new XmlSerializer(typeof(Person));
s.Serialize(outStream, this);
xmlString = outStream.ToString();
}
return xmlString;
}
}
// 2. ———————————————————————-

public string xmlString { get; set; }
public static Person p = null;

protected void Button1_Click(object sender, EventArgs e)
{
p = new Person();
p.Name = “my name”;
p.LastName = “my lastname”;
p.Age = 20;
xmlString = p.GetSerializedXml();
}

protected void Button2_Click(object sender, EventArgs e)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
DeserializeFromXML(p.GetSerializedXml(), xmlSerializer);
}

private Person DeserializeFromXML(string xmlString, XmlSerializer xmlSerializer)
{
StringReader stringReader;
stringReader = new StringReader(xmlString);
XmlTextReader xmlReader;
Person fatique = null;
xmlReader = new XmlTextReader(stringReader);
fatique = (Person)xmlSerializer.Deserialize(xmlReader);
xmlReader.Close();
stringReader.Close();
return fatique;
}