MShetty


Hi all,

is there a way we can parse a XML(file name lister) file that has a structure say,

<Node>
<Root>
<FullName>/My Documents/Documents/Feature/17470_652</FullName>
<ShortName>17470</ShortName>
<XMLFileName>17470_652.xml</XMLFileName>
<LastModifiedOn>12 December 2006</LastModifiedOn>
</Root>
...
...
...
</Node>

and get the values of all the <XMLFileName> attribute and load them into some variables,say here the filename is "17470_652.xml", I have to look for this file in a specified location, open the XML file and load the contents to a table It can be presumed that all the XML files will be stored in a same location




Re: Parse XML to load files inside them

JayH


The Foreach Loop Container can do this. Drop one onto your Control Flow and open it up. Set the Collection Enumerator to "Foreach NodeList Enumerator". Set the DocumentSourceType to FileConnection and select your "file name lister" file for the DocumentSource. EnumerationType is NodeText. OuterXPathStringSourceType is DirectInput. Set OuterXPathString to "/Node/Root/XMLFileName". Now switch the to Variable Mappings page and create a new variable (maybe name it XMLFileName) and map it to Index 0.

Now the foreach will read your file perform an iteration of the loop for each occurrence of the XMLFileName element. The value of the element (the file name) will be placed in the variable. From there you can configure a connection manager to read that file or do whatever else you need.





Re: Parse XML to load files inside them

MShetty

Thanks for the quick reply JayH will try n let it out Smile




Re: Parse XML to load files inside them

MShetty

JayH wrote:
Now the foreach will read your file perform an iteration of the loop for each occurrence of the XMLFileName element. The value of the element (the file name) will be placed in the variable. From there you can configure a connection manager to read that file or do whatever else you need.

I do have the names of all the XML files in a variable. Now how do I go about configuring the connection manager. If its a flat file connection I can go about using some expressions, but I need to load XML files. How do I get to Configure this





Re: Parse XML to load files inside them

JayH

Will you be using an XML Source instead of a Flat File Source I warn you that you are getting beyond my personal experience as I've never used the XML Source, but it seems to me that you would create a new variable to build the full path to your XML file and then use this new variable in the XML Source with the Data Access Mode set to "XML file from variable". The new variable would be set to EvaluateAsExpression so it could combine your filename with any necessary path component.






Re: Parse XML to load files inside them

MShetty

JayH wrote:
Will you be using an XML Source instead of a Flat File Source I warn you that you are getting beyond my personal experience as I've never used the XML Source, but it seems to me that you would create a new variable to build the full path to your XML file and then use this new variable in the XML Source with the Data Access Mode set to "XML file from variable". The new variable would be set to EvaluateAsExpression so it could combine your filename with any necessary path component.

Thats exactly what is being done... But can you brief on the evaluateasExpression property. I did make it as true, now I get the Expression text box, what do I do here for now when I select the data mode as Xml From variable it throws an error saying there is no valid location of an Xml here in this variable. Am sure there is something to be done in the Expresion field, is it

Thanks for the help so far Smile





Re: Parse XML to load files inside them

JayH

The expression is where you'll build a path using the filename from your variable. Example might be "c:\\temp\\" + @XMLFileName. Note that you have to double the backslashes so they aren't treated as escape sequences. Refer to the Integration Services Expression Reference for more details about building expressions.




Re: Parse XML to load files inside them

MShetty

Thanks JayH it is working... But a small query, Instead of building the path as a expression here, I used a variable to get the path from an Ini file and append with it the file name and store the entire stuff in a variable say CompleteFileName. Now when I try using this varialbe as the one in the XML Source, its faling with the error that there is no XML in the path specified. What am trying to do is make the path configurable than hard coding it Is this possible Am i Wrong somewhere..

Thanks for the help ....





Re: Parse XML to load files inside them

JayH

Getting the path from an .INI file is good. I would have suggested it, but didn't want to complicate things. Two things could be happening to give you this error. Either you haven't specified a default value for the path variable that is being set by the .INI, or maybe you're missing a backslash between the path and the filename. The .INI will only be read at run-time. You'll get a design-time error if you don't specify a default value.




Re: Parse XML to load files inside them

MShetty

JayH wrote:
The .INI will only be read at run-time. You'll get a design-time error if you don't specify a default value.

You hit the nail right on.. Passing a default value fixed the issue. Thanks a lot for all the help.