Skip to main content
nitindamle_123
Silver ⭐️⭐️⭐️
Feb 14, 2019 1:13 PM UTC
Solved

How to Convert XML file into CSV file using NIFI

i have XML files about 1-2 GB i want it to convert into CSV format using apache nifi.

so that i can process CSV for joining the two csv.

alim
alimAnswer
Gold ⭐️
Feb 14, 2019 10:53 PM UTC

Hi @Nitin Damle

You can use the ConvertRecord processor (with XMLReader/CSVRecordSetWriter controller services). I have an article here that shows CSV to XML (with CSVReader/XMLRecordSetWriter controller services), so you just need to do the inverse of that record transformation:

https://community.hortonworks.com/content/kbentry/199310/xml-record-writer-in-apache-nifi-170.html

-Andrew

22 replies

alim
Gold ⭐️
alimAnswer
Gold ⭐️
Feb 14, 2019 10:53 PM UTC

Hi @Nitin Damle

You can use the ConvertRecord processor (with XMLReader/CSVRecordSetWriter controller services). I have an article here that shows CSV to XML (with CSVReader/XMLRecordSetWriter controller services), so you just need to do the inverse of that record transformation:

https://community.hortonworks.com/content/kbentry/199310/xml-record-writer-in-apache-nifi-170.html

-Andrew

Translate
nitindamle_123
Silver ⭐️⭐️⭐️
Feb 15, 2019 1:57 PM UTC

@Andrew Lim

can you please upload the template here i have tried to upload template given in link but it throwing error

Translate
alim
Gold ⭐️
Gold ⭐️
Feb 15, 2019 11:15 PM UTC

@Nitin Damle

convert-cvs-to-xml.xml

If you are still having problems uploading the template, can you confirm what version of NiFi you are on? I just did a test in NiFi 1.8.0 and the upload was successful.

Translate
nitindamle_123
Silver ⭐️⭐️⭐️
Feb 20, 2019 4:08 PM UTC

@Andrew Lim After importing it giving me this error

106511-csvtoxmlerror.png

Translate
nitindamle_123
Silver ⭐️⭐️⭐️
Feb 20, 2019 4:11 PM UTC
max_boreback
Silver ⭐️⭐️⭐️
Feb 23, 2019 6:53 PM UTC

You can use this NIFI Groovy processor that converts XML to CSV or AVRO

https://github.com/maxbback/nifi-xml


Translate
nitindamle_123
Silver ⭐️⭐️⭐️
Feb 25, 2019 2:54 PM UTC

@Max Börebäck can you upload the template here

Translate
maxbback
Silver ⭐️⭐️
Feb 1, 2020 1:40 PM UTC

I have uploaded a NiFi example template on https://github.com/maxbback/nifi-xml

Translate
maxbback
Silver ⭐️⭐️
Jan 13, 2020 5:16 PM UTC

Depending on the complexity

But one option is to use the built in converters Another Option is to use this groovy script

 

https://github.com/maxbback/nifi-xml

 

Translate