Please enable JavaScript to view this site.

Altova MapForce 2022 Professional Edition

Altova Global Resources

Example: Run Mapping with Variable Input Files

Scroll Home Prev Top Next More

Let's assume that you frequently run a mapping that takes as input an XML file. Every time when you need to change the input XML, you can edit the properties of the source XML component and browse for the new input file, see Changing the Component Settings. This is easy to accomplish if it's a one time task. However, what if you need to change the input XML file of the mapping multiple times per day, or even per hour? For example, every morning you need to run the mapping and generate a report by using one XML file as mapping input, and every evening the same report must be generated from another XML file. This is where Global Resources can help you: instead of editing the mapping multiple times per day (or keeping multiple copies of it), you could configure the mapping to read from a file defined as a global resource (a so-called "file alias"). To address the requirement laid out in this example, the file alias could be configured to have two configurations:


1."Default" - This configuration would supply a "morning" XML file as mapping input

2."EveningReports" - This configuration would supply an "evening" XML file as mapping input.


Having these configurations in place would make it possible to run the mapping with either input file. Once the file alias is set up as shown below, you will be able to select the desired configuration from a drop-down list, before running the mapping.


Step 1: Create the Global Resource

The file alias can be created as follows:


1.On the Tools menu, click Global Resources. (Alternatively, click the Global Resource ic-globrec toolbar button.)

2.Click Add | File.

3.Enter a name in the Resource alias text box (in this example, "DailyReports" would be an appropriate name).

4.Click Browse and select the following file: <Documents>\Altova\MapForce2022\MapForceExamples\Tutorial\mf-ExpReport.xml.

5.Click Add Configuration glob-addic and name it "EveningReports".

6.Click Browse and this time select the following file: <Documents>\Altova\MapForce2022\MapForceExamples\Tutorial\mf-ExpReport2.xml.


Step 2: Use the Global Resource in the mapping

The required Global Resource has now been created; however, the mapping is not using it yet. To change the mapping so that it reads from the previously defined file alias (Global Resource), do the following:


1.Open the following mapping <Documents>\Altova\MapForce2022\MapForceExamples\Tutorial\Tut-ExpReport.mfd.

2.Right-click the header of the source component on the mapping, and select Properties from the context menu.

3.Next to Input XML file, click Browse.

4.Click Switch to Global Resources and select the file alias "DailyReports" defined previously.

5.Click Open. The input XML file path has now become altova://file_resource/DailyReports, which indicates that the path uses a Global Resource.



Step 3: Run the mapping with the desired configuration

You can now easily switch the input XML file before running the mapping, as follows:


On the Tools menu, click Active Configuration | Default, to use the file mf-ExpReport.xml as input.

On the Tools menu, click Active Configuration | EveningReports, to use the file mf-ExpReport2.xml as input.


Alternatively, select the required configuration from the Global Resources drop-down list.


To preview the mapping result with either configuration, click the Output tab and observe differences in the generated output.

© 2015-2021 Altova GmbH