XML serialization, encoding
asp.net, c#, web-services, xml, xml-serialization
Solution
1) The GetType() function returns a Type object representing the type of your object, in this case the class `clsPerson`. You could also use `typeof(clsPerson)` and get the same result. That line creates an XmlSerializer object for your particular class.
2) If you want to change the encoding, I believe there is an override of the Serialize() function that lets you specify that. See MSDN for details. You may have to create an XmlWriter object to use it though, details for that are also on MSDN:
XmlWriter writer = XmlWriter.Create(Console.Out, settings);
You can also set the encoding in the XmlWriter, the XmlWriterSettings object has an Encoding property.
Problem
``` using System; public class clsPerson { public string FirstName; public string MI; public string LastName; } class class1 { static void Main(string[] args) { clsPerson p=new clsPerson(); p.FirstName = "Jeff"; 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(); } } ``` taken from http://support.microsoft.com/kb/815813 1) ``` System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(p.GetType()); ``` What does this line do? what is GetType()? 2) how do I get the encoding to ``` <?xml version="1.0" encoding="utf-8"?> < clsPerson xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> ``` instead of ``` <?xml version="1.0" encoding="IBM437"?> <clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3 .org/2001/XMLSchema"> ``` or not include the encoding type at all?