CSharp examples for System.Xml:XML Serialization
De serialize XML String
/*============================================================================== * Copyright (c) trenhui. All rights reserved. * =============================================================================== * This code and information is provided "as is" without warranty of any kind, * either expressed or implied, including but not limited to the implied warranties * of merchantability and fitness for a particular purpose. * =============================================================================== * This code is only for study/*from w ww . ja va 2 s . co m*/ * ==============================================================================*/ using System.Xml.Serialization; using System.IO; using System; public class Main{ public static T Deserialise<T>(string pStrXMLRootName, string xml) { StringReader rd = new StringReader(xml); T deserialisedObj; XmlSerializer serialiser = CreateXMLSerializer(typeof(T), pStrXMLRootName); deserialisedObj = (T)serialiser.Deserialize(rd); return deserialisedObj; } public static T Deserialise<T>(string pStrXMLRootName, Stream stream) { T deserialisedObj; XmlSerializer serialiser = CreateXMLSerializer(typeof(T), pStrXMLRootName); deserialisedObj = (T)serialiser.Deserialize(stream); return deserialisedObj; } public static T Deserialise<T>(Stream stream) { T deserialisedObj; XmlSerializer serialiser = CreateXMLSerializer(typeof(T), null); deserialisedObj = (T)serialiser.Deserialize(stream); return deserialisedObj; } public static T Deserialise<T>(string xml) { StringReader rd = new StringReader(xml); T deserialisedObj; XmlSerializer serialiser = CreateXMLSerializer(typeof(T), null); deserialisedObj = (T)serialiser.Deserialize(rd); return deserialisedObj; } }