Implement public class CData : IXmlSerializable
using System.Xml; using System.Xml.Serialization; [Serializable] [XmlRoot("Root")] public class MyClass { [XmlElement("Country")] public string Country{ get; set; } public CData City; }
public string GetSerializedObjectXmlString(object objectToSerialize) { string sXml; XmlWriterSettings oWriterSettings = new XmlWriterSettings {OmitXmlDeclaration = true, Indent = true}; XmlSerializerNamespaces oNamespaces = new XmlSerializerNamespaces(new[] {new XmlQualifiedName("", "")}); MemoryStream ms = new MemoryStream(); XmlWriter xWriter = XmlWriter.Create(ms, oWriterSettings); try { XmlSerializer serializer = new XmlSerializer(objectToSerialize.GetType()); serializer.Serialize(xWriter, objectToSerialize, oNamespaces); sXml = Encoding.UTF8.GetString(ms.ToArray()); } catch (Exception ex) { sXml = string.Empty; } finally { xWriter.Close(); ms.Close(); } return sXml; }