How can i convert my table data to XML

I wanted to export the table data as XML but when I click on the download button, I see only the CSV file getting downloaded.

I need an XML file.
Any utility function we have in retool to do the same?

Hi Karan! I don't believe we natively support XML exporting. Retool can definitely handle exporting as CSV, TSV, JSON, XLSX, but you may be able to use an external library for this. I have not tried it myself you may be able to use something like the fast xml parser js library.

Docs for our utils.downloadFile method

Docs for using libraries in Retool

1 Like

Hi @Karan, welcome to the community :wave:

Based on @victoria's recommendation you can do something like this:

Add a custom library to your app (Settings -> Libraries -> Add) https://cdn.jsdelivr.net/npm/xml-js@1.6.11/dist/xml-js.min.js

You now have access to the Library's functions, check out their docs. In a JS query you can now do:

var tableData = table1.data // change this to your table component's data
var options = {compact: true, ignoreComment: true, spaces: 2};
var xmlResults = js2xml(tableData, options)

utils.downloadFile(xmlResults, 'data.xml')

Does that work for your use-case?

3 Likes

Thanks Victoria

Thanks John, I will try the solution provided by you and let you know if that works

1 Like