I want to save records fetched from database in an XML file,
take x number of records from XML file into a custom collection List
process them and
Here are two methods that we use to accomplish this using the XMLSerializer:
public static T FromXML(string xml)
{
using (StringReader stringReader = new StringReader(xml))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(stringReader);
}
}
public string ToXML(T obj)
{
using (StringWriter stringWriter = new StringWriter(new StringBuilder()))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
xmlSerializer.Serialize(stringWriter, obj);
return stringWriter.ToString();
}
}