Restructuring products data using multiple loop elements - Cloud - 8.0

tXMLMap

Version
Cloud
8.0
Language
English
Product
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Data Governance > Third-party systems > Processing components (Integration) > tXMLMap
Data Quality and Preparation > Third-party systems > Processing components (Integration) > tXMLMap
Design and Development > Third-party systems > Processing components (Integration) > tXMLMap
Last publication date
2024-02-20

The following scenario creates a four-component Job that restructures the products data from an XML source file ProductsIn.xml using multiple loop elements and writes the output to an XML file ProductsOut.xml.

For more technologies supported by Talend, see Talend components.

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:

<?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 manufacturer -->
	<manufacturer id="manu_1" date="2012-10-30">
		<name>DELL</name>
	</manufacturer>
	<manufacturer id="manu_2" date="2012-10-28">
		<name>HP</name>
	</manufacturer>

	<!-- Loop2 types -->
	<types model="business1">
		<type>DELL123</type>
		<manufacturer_id>manu_1</manufacturer_id>
	</types>
	<types model="business2">
		<type>HP123</type>
		<manufacturer_id>manu_2</manufacturer_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.

The expected content of the output XML file ProductsOutput.xml is as follows:

<?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>