XML Files as Global Resources
This topic explains how to use XML files as global resources. There are situations in which you may need to change an input XML file multiple times per day. For example, every morning you need to run a particular mapping and generate a report by using one XML file as a mapping input, and every evening the same report must be generated from another XML file. 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 (the so-called file alias). In this example, our file alias will have two configurations:
1.The Default configuration will supply a morning XML file as a mapping input.
2.The EveningReports configuration will supply an evening XML file as a mapping input.
To create and configure the file alias, take the steps below.
Step 1: Create a global resource
First, we need to create a file alias. Follow the instructions below:
1.Click the toolbar button (Manage Global Resource). Alternatively, go to the Tools menu and click Global Resources.
2.Click Add | File and enter a name in the Resource alias text box. In this example, we call our default configuration MorningReports.
3.Click the Browse button near the text field The Resource will point to this file and select Tutorial\mf-ExpReport.xml.
4.Click in the Configurations section and name the second configuration EveningReports.
5.Click Browse and select Tutorial\mf-ExpReport2.xml.
Step 2: Use the global resource in the mapping
Now we can use the newly created global resource in our mapping. To make the mapping read data from the global resource, take the steps below:
1.Open the Tutorial\Tut-ExpReport.mfd mapping.
2.Double-click the header of the source component to open the Component Settings dialog box.
3.Next to Input XML file, click Browse, then click Global Resources and select the file alias MorningReports. Click Open.
4.Open the Component Settings dialog box again: The input XML file path has now become altova://file_resource/MorningReports, which indicates that the path uses a global resource.
Step 3: Run the mapping with the desired configuration
You can now switch between the input XML files before running the mapping:
•To use mf-ExpReport.xml as an input, select the menu item Tools | Active Configuration | Default.
•To use mf-ExpReport2.xml as an input, select the menu item Tools | Active Configuration | EveningReports.
Alternatively, select the required configuration from the Global Resources drop-down list in the toolbar (see screenshot below).
To preview the mapping result with either configuration, click the Output pane.