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,

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.