serialize an object to XML by using Visual C#
Create a CS file: person.cs
define a class called: public class clsPerson
{
public string FirstName;
public string MI;
public string LastName;
}
and adding info for a new instance using xml serializer to xml file
code:
static void Main(string[] args)
{
clsPerson p = new clsPerson();
p.FirstName = “Alex”;
p.MI = “A”;
p.LastName = “Price”;
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType());
x.Serialize(Console.Out, p);
Console.WriteLine();
Console.ReadLine();
}
The result truns out to be a XML file with all the person informaion i just typed in. ..
Here, just the basic tutorial about XML serialize, we can use Arraylist and transfer a set of data into XML file , i hope..

Leave a Reply