In this example we have two XML feeds. One is from warehouse, second one is from catalog.
Our goal is to combine these feeds together in a specified format. Problem is that the format and units are different.
The result is printed to standard output.
Feed files/warehouse.xml
contains information about the article like dimensions and weight.
Name | Unit |
---|---|
weight |
kg |
packaging/width |
cm |
packaging/height |
cm |
packaging/depth |
cm |
Feed files/catalog.xml
contains information about the product such as its name and description.
Name | Lang |
---|---|
Nazev |
cs, en |
Our custom-made system called Hornbach has a special XML import format. It combines the data from above-mentioned feeds into nodes called THING. Each THING contains these sub-nodes:
Name | Lang |
---|---|
NAME |
en |
Name | Unit |
---|---|
WEIGHT |
g |
VOLUME |
m³ |
In the source code, we solve this problem in a few steps and get the job done in a single query files/hornbach.xq
.
- Create an empty database called
hornbach
. - Add resource
files/catalog.xml
tohornbach
. - Add resource
files/warehouse.xml
tohornbach
. - Run query
files/hornbach.xq
. - Print the result.
When you run the example, it outputs this XML feed:
<HORNBACH>
<THING>
<NAME>Shovel</NAME>
<WEIGHT>526</WEIGHT>
<VOLUME>4.896</VOLUME>
</THING>
<THING>
<NAME>Pickaxe</NAME>
<WEIGHT>6799</WEIGHT>
<VOLUME>3.344</VOLUME>
</THING>
<THING>
<NAME>Gramophone</NAME>
<WEIGHT>9192</WEIGHT>
<VOLUME>0.256</VOLUME>
</THING>
<THING>
<NAME>Chest</NAME>
<WEIGHT>7084</WEIGHT>
<VOLUME>1.08</VOLUME>
</THING>
<THING>
<NAME>Flowerpot</NAME>
<WEIGHT>5513</WEIGHT>
<VOLUME>0.56</VOLUME>
</THING>
</HORNBACH>