title: Prevent file corruption when saving xml file
body: <p>Next line sometimes is corrupting xml file and creating a zero length xml, when OutOfMemoryException has been thrown. How to prevent file corruption?</p>
  
  <pre><code>xmlDoc.Save(filename)
  </code></pre>
  
  <blockquote>
    <p>Save-Exception of type 'System.OutOfMemoryException' was thrown.
    Save-at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32
    count)    at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean
    flushEncoder)    at System.IO.StreamWriter.Write(Char value)    at
    System.Xml.XmlTextWriter.Indent(Boolean beforeEndElement)    at
    System.Xml.XmlTextWriter.AutoComplete(Token token)    at
    System.Xml.XmlTextWriter.WriteStartElement(String prefix, String
    localName, String ns)    at
    System.Xml.XmlDOMTextWriter.WriteStartElement(String prefix, String
    localName, String ns)    at System.Xml.XmlElement.WriteTo(XmlWriter w)
    at System.Xml.XmlElement.WriteContentTo(XmlWriter w)    at
    System.Xml.XmlElement.WriteTo(XmlWriter w)    at
    System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)    at
    System.Xml.XmlDocument.WriteTo(XmlWriter w)    at
    System.Xml.XmlDocument.Save(String filename)    at
    MainOptions.Save(String filename, ItemOptions options)</p>
  </blockquote>