title: writing elements to an XML file in C#
body: <p>So I'm attempting to create a large XML file of the form:</p>
  
  <pre><code>&lt;xml&gt;
      &lt;element id ="1"&gt;1&lt;/element&gt;
      &lt;element id ="2"&gt;2&lt;/element&gt;
      &lt;element id ="3"&gt;3&lt;/element&gt;
      ...
      &lt;element id ="100000000"&gt;100000000&lt;/element&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>Using C#. I can't seem to find a way to format the element to include the id in the declaration (I am not familiar with XML at all).</p>
  
  <p>Does anyone know how I could do this in C#?</p>
  
  <p>Here is my attempt:</p>
  
  <pre><code>using System;
  using System.Xml;
  using System.Linq;
  using System.Text;
  
  namespace BigXML
  {
      class Class1
      {
  
          static void Main(string[] args)
          {
  
              // Create a new file in C:\\ dir
  
              XmlTextWriter textWriter = new XmlTextWriter("C:\\Users\\username\\Desktop\\testBigXmFile.xml", null);
              textWriter.Formatting = Formatting.Indented;
              textWriter.Indentation = 3;
              textWriter.IndentChar = ' ';
              // Opens the document
  
              textWriter.WriteStartDocument(true);
  
              textWriter.WriteStartElement("xml");
              // Write comments
              for (int i = 0; i &lt; 100000000; i++)
              {
                  textWriter.WriteElementString("element id =" + '"' + i.ToString() + '"', i.ToString());
              }
  
              textWriter.WriteEndElement();
              textWriter.WriteEndDocument();
  
              textWriter.Close();
  
          }
  
      }
  }
  </code></pre>
  
  <p>Thank you, and have a nice day.</p>