I'm maintaining an old .NET 1.1 application that runs out of memory during an XSL transformation on a large data set. XML is written directly to a FileStream:
Dim xslDoc As New System.Xml.Xsl.XslTransform
Dim sourceStream As New System.IO.MemoryStream
Dim sourceStreamWriter As New System.IO.StreamWriter(sourceStream)
Try
' Load data and schema from DataSet
Dim sourceDoc As New System.Xml.XmlDocument
dataSet.WriteXml(sourceStreamWriter , XmlWriteMode.WriteSchema)
sourceStreamWriter.Flush()
sourceStream.Position = 0
sourceDoc.Load(sourceStream)
' Load XSLT
xslDoc.Load("c:\path\to\transform.xslt")
' Transform (FAILS HERE)
xslDoc.Transform(sourceDoc, Nothing, fileStream, New System.Xml.XmlUrlResolver)
Finally
schemaStreamWriter.Close()
schemaStream.Close()
End Try
I have found similar questions on the matter, but they usually describe a situation where resulting XML is written to a MemoryStream rather than a FileStream, or refer to using XslCompiledTransform, which unfortunately is only available from .NET 2.0 and up.
How do I avoid using up all the memory during transformation?
(Similar (unanswered) question here: http://vbcity.com/forums/t/151286.aspx)