Load a XML file to a variable
When I look into the XML Source component, there is an option of XMldata from varialbe, can anybody helpme in knowing how exactly do I go about in loading an XML file onto a variable ?
April 6th, 2007 7:57am

Variety of ways to load xml data from a file into a variable. Here's one: One is to use the XML task with a no-op xslt. The xsl transform doesn't do anything, so the unmodified file data ends up the variable. Operation Type: XSLT SourceType: File connection SaveOperationResult: True Destination: SomeStringVariable DestinationType: Variable OverwriteDestination: True SecondOperandType: Direct input Second Operand: Code Snippet <?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output encoding="utf-16" /> <xsl:template match="*"> <xsl:copy-of select = "." /> </xsl:template></xsl:stylesheet>
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2007 9:47am

Thanks a lot for the reply!!! Butthis is what am trying to do.. I have a variable onto which am storing the complete path location where my XML file is stored. Say "C:\\Temp\\A.xml" I also have a Stored Proc in my Database that does accept an XML doc as an input parameter. Now is there a way I can pick the XML file load it onto a variable and pass it onto the Stored Proc
April 6th, 2007 10:37am

Starting from the beginning, and attempting to get the contents of a xml file into a SQL 2k5 stored procedure's input xml parameter...So, supposing you had a source xml like the following <?xml version="1.0" encoding="utf-16" standalone="yes"?><book><chapter name="all play and no work"></chapter><chapter name="all work and no play"></chapter></book>and a stored procedure which counted up the number of chaptersCREATE PROCEDURE dbo.CountOfChapters (@doc xml)ASSET NOCOUNT ONSELECT @doc.value('count(//chapter)','int') as CountOfChaptersRETURNFirst, create an XML task, using the no-op xslt set to the following xsl transform to get the data into an IS string variable Code Snippet <?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output encoding="utf-16" /><xsl:template match="*"><xsl:copy-of select = "." /></xsl:template></xsl:stylesheet>Follow that XML task with an Execute SQL task. Use an ADO.NET SqlClient connection manager, and in the Parameter Mapings table, map the sproc's @doc input parameter to a DataType of Xml and to the String variable loaded by the XSLT task. Set the ResultProperty of the SQL task to "Single Row", mapping into an IS variable of type In32. A count of 2 is loaded into the IS variable.
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2007 1:04pm

jaegd wrote: First, create an XML task, using the no-op xslt set to the following xsl transform to get the data into an IS string variable<?xml version="1.0"?><xsltylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xslutput encoding="utf-16" /> <xsl:template match="*"> <xsl:copy-of select = "." /> </xsl:template></xsltylesheet>Follow that XML task with an Execute SQL task. Use an ADO.NET SqlClient connection manager, and in the Parameter Mapings table, map the sproc's @doc input parameter to a DataType of Xml and to the String variable loaded by the XSLT task. Set the ResultProperty of the SQL task to "Single Row", mapping into an IS variable of type In32. A count of 2 is loaded into the IS variable. Sorry to ask u again, but can you please explain a bit here ? I have a XML task, operation type i have given it as XSLT, Source type I have selected as File Connection, given a value for the source field, Selected Destination as the string variable to be passed into the SP. What is this Second operand stuff ? This is slightly confusing. Sorry if am troubling...
April 6th, 2007 4:01pm

The second operand for the XML task, when then operation is XSLT, is the Xml tranform text itself. SecondOperand is an "accurate" name, but it not a helpful one.Paste the text of the xml transform into the SecondOperand property. The problem might be that the forum's "smiley" converter trashes (by default) cut and paste of xml, xml schema, xml transforms.The xsltylesheet really should read "xsl" colon "stylesheet"The xslutput, which is an interesting conversion of what was originally pasted, should read "xsl" colon "output".
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2007 7:03pm

Try enclosingthe codein a code snippet. Code Snippet xsl:stylesheet xsl:output
April 6th, 2007 7:22pm

Thanks a lot. I'll use that from now on.
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2007 7:47pm

jaegd wrote: The second operand for the XML task, when then operation is XSLT, is the Xml tranform text itself. SecondOperand is an "accurate" name, but it not a helpful one.Paste the text of the xml transform into the SecondOperand property. The problem might be that the forum's "smiley" converter trashes (by default) cut and paste of xml, xml schema, xml transforms.The xsltylesheet really should read "xsl" colon "stylesheet"The xslutput, which is an interesting conversion of what was originally pasted, should read "xsl" colon "output". Thanks a Million it is working now.. But havea slight query over here. you had said about having the Coonection in Souce type in XML Task as File Connection right ? Am afraid it is loading only that particular XML File. How do I make it pick all the XML files in the particaular path ? Is this possible ? So close yet so far ....
April 9th, 2007 9:31am

I did try out this.. I got a varialbe totFileName that has the name of the XMl file and the complete path where it si stored, am getign this variable populated with all the xml file names, thanks to the script/for each component. I modified the source type in the XMl Task to Variable instead of File Connection, clicked on the Expressions builder and for the property souce I came up with the expression "@[User::TotFileName]" and when I clicked on the evaluate expression, I get the complete path name, "C:\\Documents and Settings\\temp\\S_ 22328_0003.xml". But when I run the package this is the error I get. "Error: Failed to lock variable "S_17470_0003b652.xml" for read/write access with error 0xC0010001 "The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.". Something am missing here ?
Free Windows Admin Tool Kit Click here and download it now
April 9th, 2007 9:40am

When processsing multiple files, use a ForEach loop container (with a File Enumerator ) with appropriate file name to variable mappings. The set of contained tasksis the same (XML Task + Execute SQL task) for this problem space. Again, there's almost always more than one way to do it; this will work.
April 9th, 2007 9:59pm

jaegd wrote: When processsing multiple files, use a ForEach loop container (with a File Enumerator ) with appropriate file name to variable mappings. The set of contained tasksis the same (XML Task + Execute SQL task) for this problem space. Again, there's almost always more than one way to do it; this will work. This is eating me head... Ok I am doing just what you have specified, I have a ForEachLoop task (node list), Inside which I wrote a Script to get the name of the XML files, and then I have one more ForEach Task with file enumerator. Set of contained task is XML+ExecuteSQl. Now my idea is try to create the directory in which my XML's are loaded dynamically using a variable, then pass the name of the XML to the XML task and load the XML into a varialbe and pass it onto the SP. Looks so simple but no luck its still giving the same error, I had posted earlier. Anyhting I am missing here. Thanks for all the help so far...
Free Windows Admin Tool Kit Click here and download it now
April 10th, 2007 11:25am

The place to put the dynamic filename expression is on the file connection manager's connectionString property. Change the source type of the connection back from Variable to File Connection on XML Task. Put the expression @[User::TotFileName] on the File Connection manager's ConnectionString property. The reason for that "variable cannot be found" error is quite simple. You have changed the SourceType on the XML Task from File Connection to Variable, and then put an expression on the XML Task's Source property.Translated, that meansthe taskis going to look for a variablenamed "S_17470_0003b652.xml", which doesn't and shouldn't exist. The interpretation of the Source property for the XML Task isbased on the Source Type (Direct Input, File connection, or Variable) When the SourceType is "Variable", the task's Source property must be the NAME of a variable, which contains xml. Naturally thereis no variable with the name "S_17470_0003b652.xml", that's the name of a file. Now, when the SourceType is "File Connection", the Source task property must be the NAME of a file connection manager, which points to a file containing xml.
April 12th, 2007 6:22am

Hi, I am facing the same issue. I have a file ABC.xml Created a XML Task and the Properties that i set: Operation Type: XSLT SourceType: File connection Source:ABC.xml SaveOperationResult: True Destination:bcd.xml(which is copy of xml) DestinationType: File connection OverwriteDestination: True SecondOperandType: File connection Second Operand: abc.xslt (which is a copy of abc.xml saved it as a .xslt) But it throwing errors: [XML Task] Error: An error occurred with the following error message: "XSLT compile error.". Please suggest something Thanks, Eshwar.
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 12:52am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics