title: More efficient use of an XMLReader
body: <p>I have the following code:</p>
  
  <pre><code>    for (i = 1; i &lt;= loopsNeeded; i++)
      {
          lblCurrent.Text = string.Format("{0} of {1}", i, loopsNeeded);
          prgWriteProgress.Value = i;
          this.Refresh();
  
          reader = XmlReader.Create(FilePath);
          outputFile = CreateXmlOutputFileName(xmlFileInfo);
          FileStream stream = new FileStream(outputFile, FileMode.Create);
  
          xslArg = new XsltArgumentList();
          xslArg.AddParam("Index", "", currentNode);
          xslArg.AddParam("BatchSize", "", batchSize);
  
          transformation.Transform(reader, xslArg, stream);
  
          currentNode+=batchSize;
  
          stream.Flush();
          stream.Close();
      }
  </code></pre>
  
  <p>This code runs through an XML file picking out a certain batch of information each time and it progressively moves through the file.</p>
  
  <p>According to MSDN:</p>
  
  <blockquote>
    <p>XmlReader provides forward-only, read-only access to a stream of XML data.</p>
  </blockquote>
  
  <p>This gives me the issue of needing to re-define the XML reader each loop to ensure it starts at the top of the file.</p>
  
  <p>Tests gave the following feedback:  </p>
  
  <pre><code>125,000 information nodes/125,000 per batch file = 48 mins.  
  125,000 information nodes/5000 per batch file = 58 mins.  
  125,000 information nodes/500 per batch file = 2 hours 33 mins.
  </code></pre>
  
  <p>As you can see there is a heavy repercussion when running smaller batch sizes due to the requirement to constantly reload an 0.8gig file into the XMLReader.</p>
  
  <p>Is there a way to avoid having to redeclare the XMLReader each time, thus reducing the overhead I encounter?</p>