I´m a programming student and I would like to know if it is possible to change the format of a date when I serialize it in a xml file. This date is an attribute of an ObservableCollection of objects "Loan", this objects have two DateTime properties, one of the dates is a nullable object. I serialize all the collection including the date.
I would like to obtain in the xml file:
<OutDate> 15-03-2014 </OutDate>
<!--If the date is null I don´t want to appear the node-->
And I´m getting this:
<OutDate>2014-03-15T00:00:00</OutDate>
<InDate xsi:nil="true" />
This is part of my code project: Part of my class Loan, already mark as serializable, looks like this:
private string isbn;
private string dni;
private DateTime dateOut;
private DateTime? dateIn;
// Setters and Gettters and constructors
This is the method for serialize:
// I will pass three collections to this method loans, books and clients
public void SerializeToXML<T>(string file, string node, ObservableCollection<T> collection)
{
XmlRootAttribute root = new XmlRootAttribute(node);
XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<T>), root);
using (FileStream fs = new FileStream(file, FileMode.Create))
{
serializer.Serialize(fs, collection);
}
}
The call:
SerializeToXML<Loan>(_file, "Library", manager.LoansCollection);
Thnks.