Follow-On Topics

Related Topics

# Runtime Processing

At runtime of the Step, the configuration options determine the structure of the XML output by the Tool.

The Tool has two modes, determined by the selection/clearing of the Auto Generate Output XML checkbox:

|  | Automatic generation of the output XML — The structure of the XML and the key fields within each level are automatically determined by the Tool

For Auto mode, a dataset containing all the recordsets and their relationships is created, and from this the XML is generated.

|  | Manual generation — The user may change the structure and key fields, which in turn affects how the data is translated into XML

During processing, for manual mode, one recordset containing all fields from all recordsets is generated, using the links defined in the configuration to mark where the recordsets are joined. This combined recordset is then turned into an XML document, using the structure of the XML and the Key Field information set up in the Output tab of the Step configuration.

For each level defined in the XML structure, one of the fields present must be designated as the key field. The combined recordset is iterated record by record, and the designated key field checked to see if the value in the record is different to the value of the field in the record before. If so, a new instance of the object at the level of the key field in the XML structure is created. It is therefore very important that the incoming recordsets are sorted correctly, by the key field values - otherwise unexpected XML output is seen.

## Example 1

A Task contains two Database Query (ODBC) Steps which obtain Account and Contact data from a CRM system. These queries return recordsets like so:

### Account Query

AccountId | Name | Sector
--- | --- | ---
1 | Customer 1 | Engineering
2 | Customer 2 | IT
3 | Customer 3 | Engineering

### Contact Query

ContactId | AccountId | FirstName | LastName
--- | --- | --- | ---
1 | 1 | Fred | Bloggs
2 | 1 | John | Smith
3 | 1 | Jane | Smith
4 | 2 | Tim | Jones
5 | 3 | Rod | Huggins
6 | 3 | Phillip | Otter

In the configuration for the Tool, both Steps are selected as input recordsets. A link is created from the `Account` to the `Contact` table, using the `AccountId` field in both tables. Auto Generation is used.

The output XML looks like this:

    <Root>
         <Account>
              <AccountId>1</AccountId>
              <Name>Customer 1</Name>
              <Sector>Engineering</Sector>
              <Contact>
                   <ContactId>1</ContactId>
                   <AccountId>1</AccountId>
                   <FirstName>Fred</FirstName>
                   <LastName>Bloggs</LastName>
              </Contact>
              <Contact>
                   <ContactId>2</ContactId>
                   <AccountId>1</AccountId>
                   <FirstName>John</FirstName>
                   <LastName>Smith</LastName>
              </Contact>
              <Contact>
                   <ContactId>3</ContactId>
                   <AccountId>1</AccountId>
                   <FirstName>Jane</FirstName>
                   <LastName>Smith</LastName>
              </Contact>
         </Account>
         <Account>
              <AccountId>2</AccountId>
              <Name>Customer 2</Name>
              <Sector>IT</Sector>
              <Contact>
                   <ContactId>4</ContactId>
                   <AccountId>2</AccountId>
                   <FirstName>Tim</FirstName>
                   <LastName>Jones</LastName>
              </Contact>
         </Account>
         <Account>
              <AccountId>3</AccountId>
              <Name>Customer 3</Name>
              <Sector>Engineering</Sector>
              <Contact>
                   <ContactId>5</ContactId>
                   <AccountId>3</AccountId>
                   <FirstName>Rod</FirstName>
                   <LastName>Huggins</LastName>
              </Contact>
              <Contact>
                   <ContactId>6</ContactId>
                   <AccountId>3</AccountId>
                   <FirstName>Phillipe</FirstName>
                   <LastName>Otter</LastName>
              </Contact>
         </Account>
    </Root>

## Example 2

A Task contains one Database Query (ODBC) Step retrieving a recordset consisting of Account and Address data. This recordset looks like this:

Code | Name | AddressId | Address_Street | Address_City
--- | --- | --- | --- | ---
Cust1 | Customer 1 | 1 | 2 Test Street | Somewhere
Cust1 | Customer 1 | 2 | 2 Another Street | Nowheresville
Cust2 | Customer 2 | 3 | 22 Acacia Avenue | Demotown

Click the image to view full size.

This Step is selected as the input data for the Tool. Manual XML structure creation is selected and in the Output tab an XML tree structure is created with an Account level and an Address level, with the fields all brought in from the Task Browser dialog box and the key fields set to the Code and AddressId fields, like this:

The output XML looks like this:

    <Root>
         <Customer>
              <Code>Cust1</Code>
              <Name>Customer 1</Name>
              <Address>
                   <AddressId>1</AddressId>
                   <Address_Street>2 Test Street</Address_Street>
                   <Address_City>Somewhere</Address_City>
              </Address>
              <Address>
                   <AddressId>2</AddressId>
                   <Address_Street>2 Another Street</Address_Street>
                   <Address_City>Nowheresville</Address_City>
              </Address>
         </Customer>
         <Customer>
              <Code>Cust2</Code>
              <Name>Customer 2</Name>
              <Address>
                   <AddressId>3</AddressId>
                   <Address_Street>22 Acacia Avenue</Address_Street>
                   <Address_City>Demotown</Address_City>
              </Address>
         </Customer>
    </Root>

Copyright © 2018 Quadrant Software B.V. All rights reserved.