Convert object to XML in C#

Sheonarayan
Posted by Sheonarayan under C# category on | Points: 40 | Views : 901
To convert an Object to XML, we can use below code snippet. The object can be a single as well as collection of objects.

var data = GetCategoryObject(); // GetCategoryObjects();

using (System.IO.StringWriter writer = new System.IO.StringWriter())
{
var serializer = new System.Xml.Serialization.XmlSerializer(data.GetType());
serializer.Serialize(writer, data);
var xml = writer.ToString();
}


Thanks

Comments or Responses

Login to post response