SSIS Foreach NodeList Enumerator

The SSIS Foreach NodeList Enumerator is useful to enumerate the XML nodes. For example, you can traverse to any node in an XML file using this enumerator. In this article, we will show you how to use this SSIS Foreach NodeList Enumerator with an example.

Before we start demonstrating the Foreach NodeList Enumerator in SSIS, Let me show you the data that we are going to use for this example. It is Employee Table present in SQL Server that we are going to use for this example:

Execute SQL Task in SSIS Full Row Set 1

Below query will convert the data in Employee table to an XML file

SSIS Foreach NodeList Enumerator 1

and the data inside the XML file is:

SSIS Foreach NodeList Enumerator 2

SSIS Foreach NodeList Enumerator Example

In this SSIS Foreach NodeList Enumerator example, we will enumerate the nodes in the above XML file, and copy the Occupation column information into another database table. To do so, First Drag and drop the Foreach Loop Container into the Control Flow region

SSIS Foreach NodeList Enumerator 3

Double click on it will open the Foreach Loop Editor to configure it. Within the SSIS General tab, Please specify valid Name and Description. Here, we assigned the name as SSIS Foreach NodeList Enumerator

SSIS Foreach NodeList Enumerator 4

Next, go to the Collections tab to select the Enumerator. Here, we are choosing Foreach NodeList Enumerator because we want to loop over the XML nodes.

SSIS Foreach NodeList Enumerator 5

The following is the list of properties that you have to configure for this SSIS Foreach NodeList Enumerator.

SSIS Foreach NodeList Enumerator 6

Document Source Type: This SSIS Foreach NodeList Enumerator property has three options:

  • File Connection: It means, the source is in an XML file present in the file system. You can use the next property to select the file.
  • Variables: Source is present in the variable. If you select this option, then you have to select the variable name in the next option.
  • Direct Input: We want to insert the XML data directly into this editor. For now, we are selecting this option.
SSIS Foreach NodeList Enumerator 7

As you can see, we inserted the above-specified XML data

SSIS Foreach NodeList Enumerator 8

Enumerator Type: This Foreach NodeList Enumerator property has four options:

  • Navigator: This will enumerate using XpathNavigator
  • Node: Enumerate nodes.
  • NodeText: This will enumerate text nodes. It is useful to narrow down your search.
  • ElementCollection: IT enumerate element nodes returned by the Xpath.
SSIS Foreach NodeList Enumerator 9

Next, we are providing the path. Below path will navigate to Occupation node present in each Employ under the Employee details node.

SSIS Foreach NodeList Enumerator 10

Now select the existing variable and assign it to index 0. Once completed, Click OK to finish configuring the Foreach Loop Container.

SSIS Foreach NodeList Enumerator 11

Next, Drag and drop the Execute SQL Task to Foreach loop container. This task helps us to insert the values into our Empty table.

SSIS Foreach NodeList Enumerator 12

Double click on it will open the Execute SQL Task Editor window. Here, we selected the OLE DB Connection type and chose the existing connection, which is pointing to [SQL Tutorials] Database.

SSIS Foreach NodeList Enumerator 13

Next, we are writing the following SQL Query to insert the table name into the SMO_Enumerator table.

INSERT INTO [NodeListEnumerator] ([Occupation])
                          VALUES (?)

Here question mark will be replaced by the parameter.

SSIS Foreach NodeList Enumerator 14

Please cross-check all the properties before you start parameter mapping

SSIS Foreach NodeList Enumerator 15

Next, go to parameter mapping and select the parameter that we assigned in the Foreach Loop container. It means the Foreach loop container will loop through the XML nodes, and store the occupation information in the variable. Next, we are passing that variable into Execute SQL task

SSIS Foreach NodeList Enumerator 16

Click OK to finish configuring the SSIS Foreach NodeList Enumerator package. Let us Run the package

SSIS Foreach NodeList Enumerator 17

Let us open the SQL Server management studio and check whether we inserted the Occupation details into the destination table using SSIS Foreach NodeList Enumerator or not

SSIS Foreach NodeList Enumerator 18