Example: Iterating Through Items
This example illustrates how to create iterations (multiple rows) in a target CSV file. The mapping design file accompanying this example is available at the following path: <Documents>\Altova\MapForce2022\MapForceExamples\Tutorial\Tut-xml2csv.mfd.
This mapping has been intentionally created as incomplete. If you attempt to validate the example file using the menu command File | Validate Mapping, you will notice that validation warnings occur. Also, if you preview the mapping output, a single row is produced, which may or may not be your intended goal.
Let's assume that your goal is to create multiple rows in the CSV file from a sequence of items in the XML file. You can achieve this by drawing a connection to the Rows item of the target CSV file.
For example, to iterate through all offices and have the output appear in the CSV file, it is necessary to connect Office to Rows. By doing this, you are instructing MapForce: for each Office item of the source XML, create a row in the target CSV file.
The Rows item in the CSV component acts as an iterator for the sequence of items connected to it. Therefore, if you connect the Office item, the output creates a row for each office found in the source XML.
In a similar fashion, if you connect Department to the Rows item, a row will be produced for each department found in the source XML.
The output would then look as follows:
Finally, mapping Person to the Rows item results in all the Persons being output. In this case, MapForce will iterate through the records as follows: each Person within each Department, within each Office.