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<T>
process them and save updated items back into XML file.
‘T’ is a simple object with value type properties, something like –
public class T
{
public int Id {get; set;}
public string property1 {get; set;}
public string property2 {get; set;}
}
Please guide me how can I save custom collection List<T> to XML file and vice-versa?
Also, because I am not sending out this XML file, will it make sense to go for XmlSerializer as suggested in some of the replies?
While you could use a serializer – and many times this is the right answer – I personally would use Linq to XML which would allow you to be more flexible on how your XML should look like, i.e. to create the following XML from a collection
foosbased on your class:You could use: