Using MemoryStream to write out to XML
问题 I have noticed two different approaches to writing out data to an XML file (error handling omitted for brevity). The first method has you build the XML document and then simply save the XML to a file: using (XmlWriter writer = XmlWriter.Create(fileName)) { writer.WriteStartDocument(true); writer.WriteStartElement("parentelement"); writer.WriteEndElement(); writer.WriteEndDocument(); } The second method has you create a MemoryStream, and then save the MemoryStream to a file: XmlWriterSettings