Return to Snippet

Revision: 2964
at May 16, 2007 14:33 by rengber

Initial Code
public static string SerializeToXmlString(object targetInstance)
            string retVal = string.Empty;
            TextWriter writer = new StringWriter();
            XmlSerializer serializer = new XmlSerializer(targetInstance.GetType());
            serializer.Serialize(writer, targetInstance);
            retVal = writer.ToString(); 
            return retVal; 
        public static object DeserializeFromXmlString(string objectXml, Type targetType)
            object retVal = null;
            XmlSerializer serializer = new XmlSerializer(targetType);
            StringReader stringReader = new StringReader(objectXml);
            XmlTextReader xmlReader = new XmlTextReader(StringReader);
            retVal = serializer.Deserialize(xmlReader); 
            return retVal; 

Initial URL

Initial Description

Initial Title
Serializing and Deserializing a Class Created with XSD.Exe Using XML Strings

Initial Tags

Initial Language