Many .NET functions use XmlWriter to output/generate xml. Outputting to a file/string/memory is a very operation:
XmlWriter xw = XmlWriter.Create(PutYourStre
The idea behind XmlWriter is to wait until you have finished modifying your data before you start writing.
XmlWriter wasn't built with your situation in mind.
Either
or