title: XmlSerializer : Generated File too big
body: <p>I have Problems with the XML Serializer in C#. My generated Files (out of a linked List Point Cloud) is getting Sizes of 30-40 MB. (60.000 Vertices).</p>
  
  <p>Most of the time my Visual Studio crashes (vshost32.exe didnt work anymore)
  Sometimes im lucky and getting this graphic issue instead:</p>
  
  <p><img src="https://i.stack.imgur.com/JCOSN.png" alt="enter image description here"></p>
  
  <p>If i redraw my Model (im using an opengl control) its suddenly displayed how it should look.
  <img src="https://i.stack.imgur.com/AZyBD.png" alt="enter image description here"></p>
  
  <p>Im guessing that my memory causes this. Is there anyway a possibility to decrease the size of the xml files? Hes using a whole line for every Tag. (460.000 Lines! )</p>
  
  <pre><code>  &lt;DistanceNeighbours /&gt;
    &lt;Vector&gt;
      &lt;X&gt;-8.52&lt;/X&gt;
      &lt;Y&gt;51.05&lt;/Y&gt;
      &lt;Z&gt;62.56&lt;/Z&gt;
    &lt;/Vector&gt;
  </code></pre>
  
  <p>Here are my Serializable + Deserializable Functions, hope you can help me.</p>
  
  <pre><code>     /// &lt;summary&gt;
      /// Serializes an object.
      /// &lt;/summary&gt;
      /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
      /// &lt;param name="serializableObject"&gt;&lt;/param&gt;
      /// &lt;param name="fileName"&gt;&lt;/param&gt;
      public void SerializeObject&lt;T&gt;(T serializableObject, string fileName)
      {
          if (serializableObject == null) { return; }
  
          try
          {
              XmlDocument xmlDocument = new XmlDocument();
              XmlSerializer serializer = new XmlSerializer(serializableObject.GetType());
              using (MemoryStream stream = new MemoryStream())
              {
                  serializer.Serialize(stream, serializableObject);
                  stream.Position = 0;
                  xmlDocument.Load(stream);
                  xmlDocument.Save(fileName);
                  stream.Close();
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine("Serialize Object Error");
          }
      }
  
      /// &lt;summary&gt;
      /// Deserializes an xml file into an object list
      /// &lt;/summary&gt;
      /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
      /// &lt;param name="fileName"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public T DeSerializeObject&lt;T&gt;(string fileName)
      {
          if (string.IsNullOrEmpty(fileName)) { return default(T); }
  
          T objectOut = default(T);
  
          try
          {
              string attributeXml = string.Empty;
  
              XmlDocument xmlDocument = new XmlDocument();
              xmlDocument.Load(fileName);
              string xmlString = xmlDocument.OuterXml;
  
              using (StringReader read = new StringReader(xmlString))
              {
                  Type outType = typeof(T);
  
                  XmlSerializer serializer = new XmlSerializer(outType);
                  using (XmlReader reader = new XmlTextReader(read))
                  {
                      objectOut = (T)serializer.Deserialize(reader);
                      reader.Close();
                  }
  
                  read.Close();
              }
          }
          catch (Exception ex)
          {
              //Log exception here
          }
  
          return objectOut;
      }
  </code></pre>
  
  <p>Thank you,</p>