title: Can JAXB Incrementally Marshall An Object?
body: <p>I've got a fairly simple, but potentially large structure to serialize.  Basically the structure of the XML will be:</p>
  
  <pre><code>&lt;simple_wrapper&gt;
     &lt;main_object_type&gt;
       &lt;sub_objects&gt;
     &lt;/main_object_type&gt;
       ... main_object_type repeats up to 5,000 times
  &lt;/simple_wrapper&gt;
  </code></pre>
  
  <p>The <code>main_object_type</code> can have a significant amount of data.  On my first 3,500 record extract, I had to give the JVM way more memory than it should need.</p>
  
  <p>So, I'd like to write out to disk after each (or a bunch of) <code>main_object_type</code>.</p>
  
  <p>I know that setting <code>Marshaller.JAXB_FRAGMENT</code> would allow it fragments, but I loose the outer xml document tags and the <code>&lt;simple_wrapper&gt;</code>.</p>
  
  <p>Any suggestions?</p>