Tuesday 5 January 2016

Data Object to XML using C#


Pass the objects into the following given method it will convert that into xml string format. In this sample XmlSerializer is used to convert the object value into string.

CODE:
private string XmlSerialize(object objValue)
{
XmlSerializer xmlSerializer = new XmlSerializer(objValue.GetType());
StringWriter textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, objValue);
return textWriter.ToString();
}