Using repeating and optional elements
You can use Test Integrations and APIs to create repeating elements within a message from a test data set or to read all values from repeating elements in a received message.
- Optional elements: Mark certain cells within the data source as containing null values so that they can be ignored when sending a message.
- Repeating elements: Determine how to group multiple rows of a data source together so that they appear within the same message.
- Repeat (additional child where tag value is null)
- Null (empty) cells are ignored, and new repeating elements are created for non-null data only. Where an element is to be repeated, the values for each occurrence of that element appear in a new row in the data source. Elements whose values are not repeated (that is, where the value appears outside the repeated element in the message) must be set to null.
- Repeat (additional child where tag value is duplicated)
- Cells that repeat data from the same column of the previous row are ignored, and new repeating elements are created for unique data only. Where an element is to be repeated, the values for each occurrence of that element appear in a new row in the data source. Elements whose values are not repeated (that is, where the value appears outside the repeated element in the message) must be set to the same value for all rows that are to be grouped together to provide values for repeated elements.
Example
The following order
element in an XML schema can be repeated multiple times in
a message.
The order
element contains a second, optional repeating
element, discountcode
.
When the entire XML schema is matched against the following test data (which is in the form of an Excel data set), five orders can be obtained.
item
element as repeating by using
Repeat (additional child where tag value is null), the message is
dynamically built from the test data set for all the five cases at the time of publishing or
subscribing. Thus, you avoid creating five tests manually, one for each structure. Following are more samples of data for which you will need to use different repeating element options; for the first one, you will use Repeat (additional child where tag value is duplicated), and for the second, Repeat (additional child where tag value is null). You can see that where additional rows are added to hold values for repeated elements, the values that are not for use inside the repeated elements are treated differently. In the first example, the fields for these items contain the same value for all the rows that are part of the same order. In the second example, values that are not for use in repeating elements are included only once. The values of such fields are left null in the subsequent rows to allow other fields to specify multiple values.