2

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,

Serge Wautier
  • 21,494
  • 13
  • 69
  • 110

1 Answers1

1

I would say: nothing for this scenario because the given stream is internally first wrapped in an XmlTextWriter and then calls the overloaded Serialize method again.

On the XmlTextWriter you can explicitly set an encoding on construction.

rene
  • 41,474
  • 78
  • 114
  • 152