I usually use this kind of code to serialize an object graph to XML:
var ser = new XmlSerializer(myObject.GetType());
using(var stream = new FileStream(filename, FileMode.Create))
{
ser.Serialize(stream , myObject);
}
(Error handling removed for clarity)
What would be the advantage of using an XmlWriter
rather than the FileStream
?
TIA,