Convert object to XML in C#

Posted by Sheonarayan under C# category on | Points: 40 | Views : 2924
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();


Comments or Responses

Login to post response