Deserialize From Xml String - CSharp System.Xml

CSharp examples for System.Xml:XML Serialization

Description

Deserialize From Xml String

Demo Code


using System.Xml.Serialization;
using System.Xml;
using System.Text;
using System.IO;/* w w  w .  j  a  v a2  s .co  m*/
using System;

public class Main{
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlContent"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object DeserializeFromXmlString(string xmlContent, Type type)
        {
            var reader = new StringReader(xmlContent);
            var xmlSerial = new XmlSerializer(type);
            object obj = xmlSerial.Deserialize(reader);
            reader.Close();
            return obj;
        }
}

Related Tutorials