title: Serialize large amount of objects in C# on the fly rather than all at once?
body: <p>I have created a couple of classes mean to represent a relational data structure ( parent child structures ). Below is an example of XML representation so far giving you an idea of what I mean</p>
  
  <pre><code>&lt;BillingFile&gt;
      &lt;Account&gt;
        &lt;acctnum&gt;122344231414&lt;/acctnum&gt;
        &lt;adjustments&gt;34.44&lt;/adjustments&gt;
        &lt;Charges&gt;
          &lt;lineitem&gt;
            &lt;chargetype&gt;PENALTY&lt;/chargetype&gt;
            &lt;amount&gt;40.50&lt;/amount&gt;
            &lt;ratecode&gt;E101&lt;/ratecode&gt;
          &lt;/lineitem&gt;
          &lt;lineitem&gt;
            &lt;chargetype&gt;LATE CHARGE&lt;/chargetype&gt;
            &lt;amount&gt;445.35&lt;/amount&gt;
            &lt;ratecode&gt;D101&lt;/ratecode&gt;
          &lt;/lineitem&gt;
        &lt;/Charges&gt;
      &lt;/Account&gt;
  &lt;/BillingFile&gt;
  </code></pre>
  
  <p>What I'm doing with my application is parsing through a large text file which could have upwards of 50,000+ accounts in it. Each time an account is read, I will create an "Account" object that has the parent objects, etc. The end goal is to be able to create an XML file containing all this account info that is serialized from the objects created.</p>
  
  <p>The problem I see with this, is that if I store all these objects in memory it will cause a performance issue as it runs in those 50k+ record files.</p>
  
  <p>What I'm wondering is, is there a way to sequentially serialize an object in C#, rather than all at once? </p>
  
  <p>I've done some googling and it seems that the built in serialization methods of .NET are a one and done kind of deal. Is there a better way I can do this? </p>
  
  <p>I'd rather avoid having to do any intermediate steps like storing the data in a database, since it's easier to modify code than it is to mess with a bunch of tables and JOIN statements.</p>
  
  <p>Thoughts?</p>