In the previous tutorial, you have converted data from a source file (books.xml) to a target file (library.xml). The target file (library.xml) did not exist before running the mapping; it was generated by the mapping transformation. Let's now imagine a scenario where you already have some data in the library.xml file, and you want to merge this data with data converted from the books.xml. The goal in this tutorial is to design a mapping that generates a file called merged_library.xml. The generated file will include data from two sources: the books.xml file and the library.xml file. Note that the files used as source (books.xml and library.xml) have different schemas. If the source files had the same schema, you could also merge their data using a different approach (see Process and Generate Files Dynamically ).
Abstract model of the data transformation
To achieve the required goal, let's take the following steps.
Step 1: Prepare the mapping design file
This tutorial uses as starting point the BooksToLibrary.mfd mapping from the <Documents>\Altova\MapForce2019\MapForceExamples\Tutorial\ folder. You have already designed this mapping in the Convert XML to New Schema tutorial. To begin, open the BooksToLibrary.mfd file in MapForce, and save it with a new name.
Make sure to save the new mapping in the <Documents>\Altova\MapForce2019\MapForceExamples\Tutorial\ folder, because it references several files from it.
BooksToLibrary.mfd (MapForce Basic Edition)
Step 2: Create a second source component
First, select the target component and copy it (press Ctrl + C), and then paste it (press Ctrl + V) into the same mapping. Click the header of the new component and drag it under the books component.
The mapping now has two source components: books and library, and one target component: library.
You can always move the mapping components in any direction (left, right, top, bottom). Nevertheless, placing a source component to the left of a target component will make your mapping easier to read and understand by others. This is also the convention for all mappings illustrated in this documentation, as well as in the sample mapping files accompanying your MapForce installation.
Step 3: Verify and set the input/output files
In the previous step, the new source component was copy-pasted from the target component, so it inherits the same settings. To ensure that the name input/output instance files are correctly set, double-click the header of each component, and, in the Component Settings dialog box, verify and change the name and the input/output files of each component as shown below.
Components settings for the first source (books)
Component settings for the second source (library)
Component settings for the target (merged_library)
As shown above, the first source component reads data from books.xml. The second source component reads data from library.xml. Finally, the target component outputs data to a file called merged_library.xml.
Step 4: Make the connections
To instruct MapForce to write data from the second source to the target, click the output connector (small triangle) of the publications item in the source library component and drag it to the input connector of the publications item in the target library component. Because the target input connector already has a connection to it, the following notification message appears.
In this particular tutorial, replacing the connection is not what we want to achieve; our goal is to map data from two sources. Therefore, click Duplicate Input. By doing so, you configure the target component to accept data from the new source as well. The mapping now looks as follows:
Notice that the publication item in the target component has now been duplicated. The new publication(2) node will accept data from the source library component. Importantly, even though the name of this node appears as publication(2) in the mapping, its name in the resulting XML file will be publication, which is the intended goal.
You can now click the Output button at the bottom of the mapping pane, and view the mapping result. You will notice that data from both library.xml and books.xml files has now been merged into the new merged_library.xml file.
© 2019 Altova GmbH