Restructuring products data using multiple loop elements
The following scenario creates a four-component Job that restructures the products data
from an XML source file ProductsIn.xml using multiple
loop elements.
These four components are:
-
tFileInputXML: reads the source products data and passes
it to the tXMLMap component. -
tXMLMap: transforms the input flow to the
expected structure streamlined. -
tLogRow: presents the execution result on the
console. -
tFileOutputXML: writes the output flow into an XML
file.
The content of the source XML file ProductsIn.xml is as
follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?xml version="1.0" encoding="ISO-8859-15"?> <products category="1" name="laptop"> <!-- Summary --> <summary> <company>DELL, HP</company> <sales unit="Dollars">12345678910.12345</sales> <model>business</model> </summary> <!-- Loop1 manufacture --> <manufacture id="manu_1" date="2012-10-30"> <name>DELL</name> </manufacture> <manufacture id="manu_2" date="2012-10-28"> <name>HP</name> </manufacture> <!-- Loop2 types --> <types model="business1"> <type>DELL123</type> <manufacture_id>manu_1</manufacture_id> </types> <types model="business2"> <type>HP123</type> <manufacture_id>manu_2</manufacture_id> </types> <!-- Loop3 sale --> <sales> <sale unit="Dollars" type="DELL123"> <quater>1</quater> <income>12345</income> </sale> <sale unit="Dollars" type="HP123"> <quater>1</quater> <income>12345.123</income> </sale> </sales> </products> |
The objective of this scenario is to restructure the products data to streamline the
presentation of the products information to serve the manufacturing operations. The expected
output data is as follows. The root element is changed to manufacturers, the sales information is consolidated into the sale element, and the manufacturer element is reduced to one single level.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="ISO-8859-15"?> <manufacturers category="1" name="laptop"> <sales unit="Dollars"> <sale sales_type="DELL123">12345.0</sale> <sale sales_type="HP123">12345.123</sale> </sales> <manufacturer id="manu_1" date="03-04-0036" name="DELL"/> <manufacturer id="manu_2" date="04-04-0034" name="HP"/> <types> <type>DELL123</type> <manufacturer_id>manu_1</manufacturer_id> </types> <types> <type>DELL123</type> <manufacturer_id>manu_2</manufacturer_id> </types> <types> <type>HP123</type> <manufacturer_id>manu_1</manufacturer_id> </types> <types> <type>HP123</type> <manufacturer_id>manu_2</manufacturer_id> </types> </manufacturers> |