When working in Power Automate, one of my team members recently asked, “How can we convert a CSV file into an XML format automatically?” This got me thinking about how common this requirement is, especially when working with integrations between systems or applications that rely on XML data structures.
In this tutorial, I will tell you how to create XML file from CSV in Power Automate with a simple scenario.
Create XML File From CSV in Power Automate
For example, I have a CSV file in the SharePoint library called ReportStorage:

Now follow the below steps:
1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

2. Add Get file content using path action to get the file from the SharePoint library and provide the below parameters:
- Site Address: Select your SharePoint site.
- File Path: Provide the path of your CSV file in SharePoint.
This action retrieves the CSV file content we want to convert.

3. Add a Compose action and provide the below expression to convert the file content (in base64 format) into a readable string:
string(body('Get_file_content_using_path'))
4. Add Compose again, leave the inputs blank, or press Enter to set the line break here.
This action prepares the flow to insert a line break to split the CSV data in the next step.

5. Add Compose action and provide the below expression:
split(outputs('Compose_|_String'),outputs('Compose_|_Line_Break'))This splits the string into rows using the line break as the delimiter. This means that each row of data from the CSV is now separate.

6. Add Compose action and provide the below expression:
split(first(outputs('Compose_|_Split')),',')This retrieves the CSV file’s first row (headers) by splitting the first item from the rows using the comma delimiter. The result is an array of column names.

7. Add the Select action and provide the below parameters:
- Form: Provide this expression:
@{skip(outputs('Compose_|_Split'),1)}This skips the first row (which contains the headers) and processes the remaining rows.
- Map: In the Map section, provide the below expression to map the headers to the row values:
{
"@{outputs('Compose_|_Field_Name')[0]}": @{split(item(),',')?[0]},
"@{outputs('Compose_|_Field_Name')[1]}": @{split(item(),',')?[1]},
"@{outputs('Compose_|_Field_Name')[2]}": @{split(item(),',')?[2]},
"@{outputs('Compose_|_Field_Name')[3]}": @{split(item(),',')?[3]}
}This expression dynamically maps each CSV column to its corresponding value in the row.

8. Add the compose action and provide the below expression:
take(body('Select'), add(length(body('Select')), -1))This removes the last item (which might be blank or unnecessary) from the array of objects.

9. Add the compose action and provide the below expression:
xml(json(concat('{"username": {"id": [',join(outputs('Compose_|_Remove_last_blank_item'),','),']}}'))) - concat(‘{“username”: {“id”: [‘, … ]}}’): Constructs the JSON structure.
- join(outputs(‘Compose-remove_last_blank_item’), ‘,’): Joins the array elements (from the previous step) into a comma-separated string.
- json(…): Converts the JSON string into a JSON object.
- XML(…): Then convert the JSON object into XML format.

10. After generating the XML, use the Create file action SharePoint to save the XML file.
- Site Address: Select your SharePoint site.
- Folder Path: Provide the path to store the XML file.
- File Name: Set the file name (e.g., ConvertedFile.xml).
- File Content: Provide dynamic content of the above-composed action.

Run the Flow to Create an XML File From the CSV
Now, click save and run the flow manually after it runs successfully. Go to the SharePoint library to see the XML file that was created successfully.
Once we open the XML file, we can see that all the CSV data have been exported to the XML file.

Conclusion
In this tutorial, we successfully converted a CSV file stored in a SharePoint library into an XML file using Power Automate. We transformed the CSV data into a structured XML format by retrieving the file content, splitting the data into rows and columns, and mapping the headers to values. Finally, we saved the generated XML file and returned it to SharePoint.
Related Power Automate tutorials:
- Check if a field exists in Power Automate
- Merge Arrays in Power Automate
- Convert XML to CSV using Power Automate
- Convert HTML to Text using Power Automate
- Convert string to Date using Power Automate

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.
Hi! the select does not work, when I use the recommended input I received the following error message:
The execution of template action ‘Select’ failed: The evaluation of ‘query’ action ‘where’ expression ‘{
“@{outputs(‘Compose_-get_field_name’)[0]}”: “@{split(item(),’,’)[0]}”,
“@{outputs(‘Compose_-get_field_name’)[1]}”: “@{split(item(),’,’)[1]}”,
“@{outputs(‘Compose_-get_field_name’)[2]}”: “@{split(item(),’,’)[2]}”,
“@{outputs(‘Compose_-get_field_name’)[3]}”: “@{split(item(),’,’)[3]}”
}’ failed: ‘The template language expression ‘split(item(),’,’)[1]’ cannot be evaluated because array index ‘1’ is outside bounds (0, 0) of array.
do you know how might I fix this in order to complete the flow and convert the csv to xml?
thanks in advance
sofia