title: Generating XML in C# ( using a class generated from XSD)
body: <p>I am trying to generate an <code>.xml</code> file using C#. I am using a class generated from an XSD for this purpose.</p>
  
  <p>To be precise I am doing some experiment with <a href="http://www.nunit.org/docs/2.2/files/Results.xsd" rel="nofollow">Nunit <code>results.xsd</code></a>.</p>
  
  <p>I need to generate some elements multiple times. I have below code at end of each function</p>
  
  <pre><code> var serializer = new XmlSerializer(typeof(resultType));
    using (var stream = new StreamWriter(@"C:\test.xml",true))
  serializer.Serialize(stream, data);
  </code></pre>
  
  <p>When I execute this multiple times, I am seeing the <code>xml</code> tag with XML version and encoding getting appended every time.</p>
  
  <p>How can I put them as a individual functions so that I can call the objects  multiple times for creating multiple XML elements of same type and in the end save the XML with data? I need the generated file to have structure similar to Nunit's results XML file.</p>