Serialize an object to XML

You have to use XmlSerializer for XML serialization. Below is a sample snippet. XmlSerializer xsSubmit = new XmlSerializer(typeof(MyObject)); var subReq = new MyObject(); var xml = “”; using(var sww = new StringWriter()) { using(XmlWriter writer = XmlWriter.Create(sww)) { xsSubmit.Serialize(writer, subReq); xml = sww.ToString(); // Your XML } } As per @kiquenet request for generic class: … Read more

Proper way to implement IXmlSerializable?

Yes, GetSchema() should return null. IXmlSerializable.GetSchema Method This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return a null reference (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the XmlSchemaProviderAttribute to the class. For both read and write, the … Read more