XmlSerializer Util
using System.IO; using System.Xml.Serialization; public class XmlUtils { public static T DeserializeXml<T>(string xmlFragment) { if (xmlFragment == null || xmlFragment.Trim().Length == 0) { return default(T); } using (StringReader reader = new StringReader(xmlFragment)) { XmlSerializer serializer = new XmlSerializer(typeof(T)); return (T)serializer.Deserialize(reader); } } public static string SerializeXml(object instance) { TextWriter writer = new StringWriter(); XmlSerializer serializer = new XmlSerializer(instance.GetType()); serializer.Serialize(writer, instance); return writer.ToString(); } }