Explain how to use XML to Serialize an object
1. Use the namespace “System.Xml.Serialization”.
2. Create a class whose object is to be serialized
3. Create an object of the class for example
Class1 c = new Class1();
4. Set the properties of the Class1 using the object c.
- c.name=”abc”;
-. c.age=10;
5. Create an instance of XmlSearializer
XmlSerializer x = new XmlSerializer(c.GetType());
TextWriter txtWrite = new StreamWriter( @"c:\test.xml" );
6. Use the xmlserializer instance to serialize the object to xml
x.Serialize(txtWrite,c);
7. Execute the project to verify