c# - Using MemoryStream to write out to XML -


I've noticed two different methods for writing data in an XML file (except for error management, leaving error management has given).

The first method is that you have created an XML document and then just saved the XML in a file:

 using  (XMLR author = XMLRR.Creative (Filename)) {writer.WriteStartDocument (true); Author.WriteStartElement ("parentelement"); Writer.WriteEndElement (); Writer.WriteEndDocument (); }  

In the second method, you have created MemoryStream, and then save MemoryStream to a file:

  XmlWriterSettings Settings = New XMLmlr settings (); Settings.Indent = true; Memorystream ms = new memorystream (); (XML Author Writer = XmlWriter.Create (MS, Settings)) (Writer. WriteStartDocument (true); writer.WriteStartElement ("parentelement"); writer.WriteEndElement (); writer.WriteEndDocument ();} (filestream) FS = Open file (Filename, File MOD.Creative, FilexVirate)) {ms.WriteTo (fs); ms.Dispose ();}  

I use MemoryStream Guessing the logic for this is to ensure that the XML file can be created before saving the file. An atom gives a writing event and / or protects the issues of writing when you are adding entries to the XML file?

Can anyone explain that it is really necessary or Is there an overkill way to add just the unnecessary lines of code to my project?

memorystream < / Code> version is useless on this occasion memorystream is useful if you have Stream -like work, but do not want to file actual if you are typing a file, then just type the file. This avoids the need to buffer all the data in memory.


Comments