Table of Contents

Search

  1. Preface
  2. Introduction
  3. Dashboard
  4. Resources
  5. Workflows
  6. Task Reference
  7. Services Overview
  8. Users
  9. Logs and Reports
  10. Encryption
  11. System
  12. Appendix
  13. Glossary Terms

Example 2: Write XML Task Using IF Element

Example 2: Write XML Task Using IF Element

The XML IF element is used to write XML elements based on Primary Key/Foreign Key or Header/Detail relationships. The test condition only compares the value from one RowSet variable to the value from another RowSet variable. The two valid comparison operators are 'eq' (equals) and 'ne' (not equals).
Example Test Condition: ${orderHeader[OrderNum]} eq ${orderDetails[OrderNum]}
In the following example, RowSet data from two SQL Query tasks will be written to a single XML file. The 'orderHeader' RowSet data will be merged with the 'orderDetails' RowSet data using the 'OrderNum' column as the primary key. This task will be accomplished using two nested loops.  The outer For-Each element will loop through the 'orderHeader' variable while the inner For-each element will loop through the 'orderDetails' loop.
Here is an example of the 'orderHeader' RowSet data. The rows have been color-coded to illustrate the relationship of the 'OrderNum' column with the data in the 'orderDetails' RowSet:
${orderHeader} RowSet Variable
${orderHeader[OrderNum]}
${orderHeader[TotShipped]}
${orderHeader[TotCharge]}
25565
3
50
25566
2
100
25567
3
50
Here is an example of the 'orderDetails' RowSet data:
${orderDetails} RowSet Variable
${orderDetails[OrderNum]}
${orderDetails[PartNumber]}
${orderDetails[TotPieces]}
${orderDetails[TotCharge]}
25565
WC0324
1
20
25565
CBJS01
1
20
25565
GBVVVDS
1
10
25566
DVBF066
2
100
25567
CBJS01
2
40
25567
GBVVVDS
1
10
Use the following instructions to create an XML file using the Write XML IF element:
  1. From within the Project Designer page, expand the Data Translation folder in the Component Library, and then drag the Write XML task to the Project Outline.
  2. On the Basic tab of the Write XML task, specify the Output File value:
    Output File
    The file path and file name of the XML file to write.
  3. In the Write XML task window, from the
    Add
    button in the sub-menu, click
    Element
    . The first Element in the Project Outline will become the root node in the XML document.
  4. On the Basic tab of the Element, specify a value for the following attributes:
    Name
    The element name as it will appear in the output XML file. An element is an XML tag. For example, <tagName>.
    Enclose in CDATA
    Whether or not the text in the Value attribute should be wrapped in CDATA tags.
  5. In the Element window, from the
    Add
    button in the sub-menu, click
    For-Each
    . The XML Write task's For-Each element iterates through each row in a RowSet variable. The first For-Each (outer loop) element in this example loops through the 'orderHeader' RowSet variable.
  6. On the Basic tab of the For-Each element, specify the Input RowSet Variable value:
    Input RowSet Variable
    The name of a variable of type RowSet which contains data to write to a file. For example, ${variableName}.
  7. In the For-Each window, from the
    Add
    button in the sub-menu, click
    Element
    .
  8.  On the Basic tab for the Element, specify the Name value:
    Name
    The element name as it will appear in the output XML file. An element is an XML tag. For example, <tagName>.
  9. In the Element window, from the
    Add
    button in the sub-menu, click
    Attribute
    .
  10. On the Basic tab of the Attribute element, specify values for the following attributes:
    Name
    The attribute name as it will appear in the output XML file. For example, <element attributeName="attributeValue" />.
    Value
    The value of this attribute. This may be expressed by a combination of constant values and RowSet column references. For example ${RowSetVariable[OrderNum]}, where RowSetVariable is the name of the variable of type RowSet andOrderNum is the column index name of that RowSet. Please note that only RowSets which are in use by a parent For-Each element may be used.
  11. Form the Project Outline, select the 'order' element created in step 9. In the 'order' Element window, from the
    Add
    button in the sub-menu, click
    For-Each
    . The second For-Each element (inner loop) in this example loops through the 'orderDetails' RowSet variable.
  12. On the Basic tab of the For-Each element, specify the Input RowSet Variable value:
    Input RowSet Variable
    The name of a variable of type RowSet which contains data to write to a file. For example, ${variableName}.
  13. From the Project Outline, select the element above the attribute, and from the
    Add
    button in the sub-menu, click
    If
    .
  14. On the Basic tab of the If element, specify a value for the following attributes:
    Test Condition
    The comparison between the value of one RowSet variable to another. In this example, the data in the 'OrderNum' column is being compared with the 'orderHeader' and 'orderDetails' RowSets. If the value of the two variables are equal, the next element in the Write XML task will be written to the XML file.

    Example Test Condition: ${orderHeader[OrderNum]} eq ${orderDetails[OrderNum]}
  15. In the IF window, from the
    Add
    button in the sub-menu, click
    Element
    .
  16. On the Basic tab of the Element, specify a value for the following attributes:
    Name
    The element name as it will appear in the output XML file. An element is an XML tag. For example, <tagName>.
  17. In the Element window, from the
    Add
    button in the sub-menu, click
    Attribute
    .
  18. On the Basic tab of the Attribute element, specify values for the following attributes:
    Name
    The attribute name as it will appear in the output XML file. For example, <element attributeName="attributeValue" />.
    Value
    The value of this attribute. This may be expressed by a combination of constant values and RowSet column references. For example ${RowSetVariable[OrderNum]}, where RowSetVariable is the name of the variable of type RowSet and OrderNum is the column index name of that RowSet. Please note that only RowSets which are in use by a parent For-Each element may be used.
  19. Form the Project Outline, select the 'part' element created in step 17. In the 'part' Element window, from the
    Add
    button in the sub-menu, click
    Element
    .
  20. On the Basic tab of the Element, specify a value for the following attributes:
    Name
    The element name as it will appear in the output XML file. An element is an XML tag. For example, <tagName>.
    Value
    The value of this attribute. This may be expressed by a combination of constant values and RowSet column references. For example ${RowSetVariable[OrderNum]}, where RowSetVariable is the name of the variable of type RowSet andOrderNum is the column index name of that RowSet. Please note that only RowSets which are in use by a parent For-Each element may be used.
  21. Form the Project Outline, select the 'part' element created in step 16. In the 'part' Element window, from the
    Add
    button in the sub-menu, click
    Element
    .
  22. On the Basic tab of the Element, specify a value for the following attributes:
    Name
    The element name as it will appear in the output XML file. An element is an XML tag. For example, <tagName>.
    Value
    The value of this attribute. This may be expressed by a combination of constant values and RowSet column references. For example ${RowSetVariable[OrderNum]}, where RowSetVariable is the name of the variable of type RowSet andOrderNum is the column index name of that RowSet. Please note that only RowSets which are in use by a parent For-Each element may be used.
  23. Click the
    Save
    button when finished.

0 COMMENTS

We’d like to hear from you!