Multiple Sources to Multiple Targets
This tutorial shows you how to map data from multiple source files to multiple target files in the same transformation. To illustrate this technique, we will create a mapping with the following goals:
1.To read data from multiple XML files in the same directory.
2.To map the schema of each file to a new schema.
3.For each source XML file, to generate a new XML target file with the new schema.
4.To strip the XML and namespace declaration from the generated files.
The image below illustrates an abstract model of the data transformation used in this tutorial:
Starting point
We will use three source XML files as examples. They are named BookTitle1.xml, BookTitle2.xml, and BookTitle3.xml. Each of the three files is based on Books.xsd and stores a single book (see below).
BookTitle1.xml
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Books.xsd">
<book id="1">
<author>Mark Twain</author>
<title>The Adventures of Tom Sawyer</title>
<category>Fiction</category>
<year>1876</year>
</book>
</books>
BookTitle2.xml
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Books.xsd">
<book id="2">
<author>Franz Kafka</author>
<title>The Metamorphosis</title>
<category>Fiction</category>
<year>1912</year>
</book>
</books>
BookTitle3.xml
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Books.xsd">
<book id="3">
<author>Herman Melville</author>
<title>Moby Dick</title>
<category>Fiction</category>
<year>1851</year>
</book>
</books>
Further steps
This is how we are going to proceed:
1.First of all, we need to map the source schema (Books.xsd) to the target schema (Library.xsd).
2.After the transformation, the mapping will generate three files according to this new schema (see code listings below).
3.We will also configure the mapping so that the names of the generated files will be Publication1.xml, Publication2.xml, and Publication3.xml. Notice that the XML declaration and the namespace declaration must be stripped.
Publication1.xml
<library>
<publication>
<id>1</id>
<author>Mark Twain</author>
<title>The Adventures of Tom Sawyer</title>
<genre>Fiction</genre>
<publish_year>1876</publish_year>
</publication>
</library>
Publication2.xml
<library>
<publication>
<id>2</id>
<author>Franz Kafka</author>
<title>The Metamorphosis</title>
<genre>Fiction</genre>
<publish_year>1912</publish_year>
</publication>
</library>
Publication3.xml
<library>
<publication>
<id>3</id>
<author>Herman Melville</author>
<title>Moby Dick</title>
<genre>Fiction</genre>
<publish_year>1851</publish_year>
</publication>
</library>
To carry out the required data transformation, take the steps described in the subsections below.