Table of Contents

Search

  1. Preface
  2. Transformations
  3. Source transformation
  4. Target transformation
  5. Access Policy transformation
  6. Aggregator transformation
  7. B2B transformation
  8. Chunking transformation
  9. Cleanse transformation
  10. Data Masking transformation
  11. Data Services transformation
  12. Deduplicate transformation
  13. Expression transformation
  14. Filter transformation
  15. Hierarchy Builder transformation
  16. Hierarchy Parser transformation
  17. Hierarchy Processor transformation
  18. Input transformation
  19. Java transformation
  20. Java transformation API reference
  21. Joiner transformation
  22. Labeler transformation
  23. Lookup transformation
  24. Machine Learning transformation
  25. Mapplet transformation
  26. Normalizer transformation
  27. Output transformation
  28. Parse transformation
  29. Python transformation
  30. Rank transformation
  31. Router transformation
  32. Rule Specification transformation
  33. Sequence transformation
  34. Sorter transformation
  35. SQL transformation
  36. Structure Parser transformation
  37. Transaction Control transformation
  38. Union transformation
  39. Vector Embedding transformation
  40. Velocity transformation
  41. Verifier transformation
  42. Web Services transformation

Transformations

Transformations

XML conversion example

XML conversion example

You have product data in an XML file that you want to convert to XML of a different format.
The XML file that you want to convert, products.xml, contains data in the following format:
<?xml version="1.0" encoding="UTF-8"?> <document> <product> <id>1</id> <name>milk</name> <size>16 oz</size> </product> <product> <id>2</id> <name>water</name> <size> 8 oz</size> </product> </document>
You want to convert the XML so that each product is in its own element, for example,
<milk>...</milk>
. You also want to append a timestamp in a comment inside the XML file.
To convert the file, first create a source file that contains the path to the XML file that you want to convert so that the mapping can read data from the XML file. Then, create the mapping.
Create a text file called "filepath.txt" that contains the following line:
C:\XMLSources\products.xml
After you create the source file, create the mapping. The following image shows the mapping:
The mapping contains a Source transformation that is connected to a Velocity transformation that is connected to a Target transformation.
Configure the transformations in the following ways:
Source transformation
Configure the Source transformation to read data from the file that contains the file path, and configure the source formatting options.
On the
Source
tab, select a connection that can access the source file, set the source type to
Single Object
, and select filepath.txt as the source object.
Click
Formatting Options
and then configure the following properties:
Property
Value
Flat File Type
Delimited
Text Qualifier
None
Field Labels
Auto-generate
First Data Row
1
Velocity transformation
Configure the Velocity transformation input and create the template.
On the
Input Format
tab, configure the following properties:
Property
Value
Input Field
Incoming string field from the Source transformation.
Input Type
File
Format Type
XML
Variable Name in Template
root
Code Page
UTF-8
On the
Velocity Template
tab, enter the following template in the template editor and validate the syntax:
<?xml version="1.0" encoding="UTF-8"?> <!--Generation date: $function.call('Systimestamp')--> ## Convert each product to an element: <products> #foreach ($child in $root.getRootElement().getChildren() ) <$child.getChild("name").getText()> <id>$child.getChild("id").getText()</id> <size>$child.getChild("size").getText()</size> </$child.getChild("name").getText()> #end </products>
Target transformation
Configure the Target transformation to write data to a flat file target created at run time. To ensure that the target file contains no header and no text qualifier character, configure the formatting options.
On the
Target
tab, select the connection and set the target type to
Single Object
. Click
Select
next to the
Object
field. Select
Create New at Runtime
, and enter the file name "products_converted.xml."
Click
Formatting Options
and set the text qualifier to
None
.
In the Advanced properties, set the header options to
No Header
.
When you run the mapping, the target file, products_converted.xml, contains the following XML:
<?xml version="1.0" encoding="UTF-8"?> <!--Generation date: 06/17/2020 17:45:41.341526--> <products> <milk> <id>1</id> <size>16 oz</size> </milk> <water> <id>2</id> <size> 8 oz</size> </water> </products>

0 COMMENTS

We’d like to hear from you!