How Do I Extract a Single Data Element from a Multi-Occurrence Compound? (Magic xpi 4.13)
Sometimes, you might need to extract a particular record from a multi-occurrence compound. The following example explains how to get the name of a specific account from a Source file.
Extracting a single data element from a multi-occurrence compound:
After you have dragged a Data Mapper into the Studio’s flow area, the first tcahing you need to do is to configure the Data Mapper’s Source properties, as follows:
-
Double-click or right-click on the Data Mapper and click Configuration to open the Data Mapper window.
-
From the Toolbox's Mapper Schemas section, drag an XML type into the Source area of the Data Mapper window.
-
In the XML Source's Properties pane, select the required XSD file (in this case, Accounts.xsd).
-
You need to define where you will take the data from, which, in this case, is a file called Accounts.xml. In the Source Type parameter, select File from the drop-down list.
-
Open the Expression Editor with the button, and enter the following expression: EnvVal ('currentprojectdir')&'Data/Accounts.xml'
This expression tells the Source to look for a data file called Accounts.xml in the current project directory.
-
Click OK to close the Expression Editor.
Once you have configured the Data Mapper’s Source properties, the next step is to configure the Destination properties, as follows:
-
From the Toolbox's Mapper Schemas section, drag a Variable type into the Destination area of the Data Mapper window.
-
In the Variable Destination's Properties pane, select the C.UserString context variable.
-
Click OK to close the Destination Properties window.
Next, you need to map the Source data to the Destination data, as follows:
-
In the Data Mapper window's Source pane, right-click on the Name node and select Connect. Then drag the mouse to the C.UserString node in the Destination pane, and click. These simple nodes, along with their respective parent compound nodes, will then be shown as connected in the Data Mapper window.
Our XML Source file contains three different accounts (as shown below). The phone numbers in the XML are not relevant for this example, so you can ignore them.
The next step is to create a condition on the Destination side to extract the name of the account whose ID value is 3:
-
Right-click on the Instance compound node in the Destination pane and select Show Properties.
-
In the node's Properties pane’s Condition parameter, click the button to open the Expression Editor.
-
In the Expression Editor, click the button and select the correct path for the ID node from the list.
-
Click OK to close the Expression Editor.
-
In the flow area, set a breakpoint, and then debug the flow by right-clicking on the flow in the Solution Explorer and selecting Debug.
-
Run your project by clicking the Run button on the toolbar.
-
Click the Context View button on the toolbar to open the Context View window.
-
Here, select the Context Variable tab and look in the Name column for the C.UserString variable. Remember that you previously selected this variable in the Destination Properties dialog box to hold the results data. This variable will display the name of the account that you wanted to extract from the Source file in its Value column. In this example, the account’s name is Account3.