Created on 06-25-2018 06:31 PM - edited 08-17-2019 07:07 AM
About a year ago, I wrote an article that detailed how to use the ConvertRecord processor and Record Reader/Writer controller services to easily convert a CVS file into various formats (JSON, Avro, XML):
At the time, the CSV to XML conversion was done using a ScriptedRecordSetWriter. With the release of NiFi 1.7.0, the CSV to XML conversion can be done much more simply with the new XMLRecordSetWriter.
This tutorial was tested using the following environment and components:
Here is a template of the flow discussed in this tutorial:
Here is the CSV file used in the flow:
Note: Change the extension from .txt to .csv after downloading.
Start NiFi. Import the provided template and add it to the canvas.
You should see the following flow:
Note: After importing the template, create or make sure the directory paths for the GetFile and PutFile processors exist, confirm users.csv is in the input directory and enable all Controller Services before running the flow:
Details of the original flow are covered in my previous HCC article, but here are the key changes made:
ConvertRecord - CSVtoXML (ConvertRecord Processor)
Record Reader is still set to "CSVReader" but Record Writer is now set to the new "XMLRecordSetWriter":
XMLRecordSetWriter Controller Service
Here are the properties for this controller service:
Besides the default values, Schema Access Strategy property is set to "Use 'Schema Name' Property", Schema Registry is set to AvroSchemaRegistry and Name of Root Tag is set to "record".
Running this updated flow now produces a flowfile with XML contents:
Created on 02-17-2020 10:28 PM
Hi Alim,
Your solution works fine for me except the xml file content is coming in one single line instead of blocks. Any idea why?
Created on 06-15-2020 07:52 PM
Help, I want to do a transformation from a flat file to a custom XML in nifi. Some example. The result should be like the picture
Created on 06-15-2020 10:48 PM
@JeanGuzman , As this is an older article, you would have a better chance of receiving a resolution by starting a new thread. This will also provide the opportunity to provide details specific to your environment that could aid others in providing a more accurate answer to your question.