Example: Split Database Table into Many XML Files
This example shows you how to generate dynamically multiple XML files, one for each record of a database table. The accompanying mapping for this example is available at the following path: <Documents>\Altova\MapForce2023\MapForceExamples\Tutorial\PersonDB-dyn.mfd.
The source database file (available in the same folder as the mapping) includes a Person table which contains 21 records. The aim of the example is to generate a separate XML file for each record in the Person table.
As the "PrimaryKey" field uniquely identifies each person in the table, this is the item we will use to split up the source database into separate files. To achieve the goal of this example, do the following:
1.Insert a concat function (you can drag it from the core | string functions library of the Libraries pane).
2.Insert a constant (on the Insert menu, click Constant) and enter ".xml" as its value.
3.Click the File ( ) or File/String ( ) button of the target component and select Use Dynamic File Names Supplied by Mapping.
4.Create the connections as shown below and then click the Output pane to see the result of the mapping.
PersonDB-dyn.mfd (MapForce Professional Edition)
Note that the resulting output files are named dynamically as follows:
•The PrimaryKey field supplies the first part of the file name (for example, "1").
•The constant supplies the file extension (".xml"), thus "1.xml" is the file name of the first file.