Input: My input files are XML files. They are read by the foreach file enumerator in SSIS.
Process: An SSIS script component (C#) reads the file name from the variable. I created an XSL file for transforming the XML into the format necessary. The script task uses the XSL file, and transforms XML files (to text)
Here is the piece of code I used:
public override void CreateNewOutputRows()
{
XslCompiledTransform transformer = new XslCompiledTransform();
transformer.Load(_xsltFile);
transformer.Transform(_fileName, @"C:\macro3\outputTestFile.txt");
}
Problem:
As expected, this writes the transformed text content to the mentioned output file. I want to read through each line, process it, and load to database.
Now, writing to a file, reading it again is an overhead.
Is there a way I can read the transformed content into any object and iterate over it (without actually writing to a file)? Like a Stream or something?
Alternatively:
Though SSIS "XML Task" has "Operation Type = XSLT" feature, it is not reading the XML if the "SourceType" is variable and I give file name with path in the variable. It is expecting the XML content in the variable. Any work around possible?
Please ask for specific details in comments, so I can update accordingly. Thank you.
I am not able to edit the Expressions of the XML task as shown in the image
Instead of using the Script Task, use a Data Flow. The Data Flow is for transforming streams of data in memory, so sounds like exactly what you're after.
A couple of options:
Either way, make sure you set the destination to "fast load" to speed things up.
While you won't need it if you decide to do this entirely in a Data Flow, as far as the XML Task goes, you need to use File connection as the source instead of Variable. MSDN notes that Variable is only for use with a variable that holds the XML content. You'll need to set up an expression in the same way you would for any file source, and pass the file path variable in.