Posts

Showing posts with the label XMLAttribute

how to serialize an object to XML, and vice versa

Hi, Here is code sample of Serializing and Deserializing.There is also some additional methods to convert Byte Array in the sample. i use serialize and deserialize actions by generic in C# private Byte[] StringToUTF8ByteArray(String pXmlString) { UTF8Encoding encoding = new UTF8Encoding(); //UTF8Encoding is under the System.Text namespace Byte[] byteArray = encoding.GetBytes(pXmlString); return byteArray; } private String UTF8ByteArrayToString(Byte[] characters) { UTF8Encoding encoding = new UTF8Encoding(); String constructedString = encoding.GetString(characters); return (constructedString); } private string Serialize(T request) { //MemoryStream is in System.IO //XMLSerializer is in System.Xml.Serialization using (MemoryStream memoryStream = new MemoryStream()) { XmlSerializer xs = new XmlSerializer(typeof(T)); XmlTextWriter