title: .Net Transforming large XML docs with XSL
body: <p>Question:  What is the best way to transform a large XML document (>200MB) using XSL in .Net?</p>
  
  <p>Background:
  I have a application that feeds me large data files, I cannot change the format.  In the past I have been able to translate smaller data files with no issues.</p>
  
  <p>Originally I was working with the XML as strings and was running out of memory very quickly.  I switched my code and now I deal with MemoryStream's to read, transform using a stylesheet and then save off a copy of the output to a separate location using filestreams.</p>
  
  <p>Applying of the stylesheet causes the application to consume upwards of 1gb memory and eventually crashes.</p>
  
  <p>I know I could programatically process the XML using the DOM but I would really like to stick with a generic method of applying an XSL stylesheet.  </p>
  
  <p>Does anyone have any pointers on how I could better manage memory while processing the XSL transformation?  Below is a snippet of code where i am applying the transformation:</p>
  
  <pre><code>'xmlData is a memory stream passed into a function 
          '...
      Dim strfilepath As String = appConfigSettings.FilePaths.XslFilePath &amp; "\" &amp; odtrow.formatterXsl
  
   Dim xslt As New System.Xml.Xsl.XslCompiledTransform()
   xslt.Load(strfilepath)
  
   Dim xmlRead As XmlReader = XmlReader.Create(xmlData)
  
   newStream = New MemoryStream()
   xslt.Transform(xmlRead, Nothing, newStream) 'here is where it fails
   newStream.Position = 0
          '...
  </code></pre>
  
  <p>C# or VB examples are fine I can work with either...This app was a hand me down so not criticism for the vb please :)
  -J</p>