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.

Consider the following scenario: You have a message that contains optional elements that do not appear in all messages or elements that are repeated multiple times in a message with different values. You might have a combination of optional elements and repeating elements, or even repeating elements within repeating elements. For example, a message containing an order for books might have either a billing address or a shipping address or both. The same order might have many discount codes applied to it. In this case, a message schema might specify that particular elements repeat, with specified minimum and maximum occurrences. However, the data cannot be put into a single row of a data source.
  • 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.
Repeating elements can come from a schema (for example, XSD) or you can mark them manually (for example, plain XML or JSON). To mark an element as repeating, right-click it and click either of the following options:
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 data spreadsheet includes multiple rows for orders that contain repeating elements.

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.

The data spreadsheet includes multiple rows for orders that contain repeating elements.
In this example, if you mark the 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.
More sample data sources:

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.