How to Convert XML to Array in Power Automate?

This Power Automate tutorial will show how to convert XML to an array in Power Automate or Microsoft Flow.

For example, we will create a flow that will convert the given XML file content to an array, by parsing the XML file content, like below.

How to convert xml file to Array using Power automate

For this, we will create an Instant cloud flow in Power Automate, that will take an XML file as user input. Then parse the file content of that XML file, loop through each node of XML data, and append to an array.

How to convert XML to an array using Power Automate

Here we will see how to convert an XML to an array using Power Automate.

Let’s create an Instant cloud flow, that will convert XML to an array using Power Automate.

Step 1: Log in to Power Automate and click the +Create icon in the left navigation -> select Instant Cloud Flow.

Microsoft Power Automate xml to Array

Then provide the flow name, and select the Manually trigger a flow. Then click on Create.

Power Automate xml to Array

Next, you can see Manually trigger a flow is added to the flow page. Then we will add the file as user input, so click on the +Add an input -> select File options.

MS flow xml file to Array

Step 2: Now we will convert the base64 to string using Power Automate, so, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression:
base64ToString(triggerBody()?['file']?['contentBytes'])
MS flow xml file to Array

Step 3: Next, click on the +New step, and select Initialize variable action. Then provide the below information:

  • Name: Provide the variable name.
  • Type: Select the type as an Array.
MS Power Automate xml file to Array

Step 4: Now, we will parse the XML data, so, click on the +New step -> select Compose action. Then provide the below information.

  • Inputs: Provide the below information:
xpath(xml(outputs('Compose_-_base_64_to_string')), '/products/product')
How to xml file to Array MS flow

Step 5: Now we will loop through person nodes to get the details, so click on the +New step -> select Apply to each action. Provide the below information:

  • Select an output from previous steps: Select the output of the previous compose, from the dynamic content.
See also  How to Convert XML to SharePoint List using Power Automate?

Next, we will Add an action -> select Compose action, then provide the below information:

  • Inputs: Provide the below expression
items('Apply_to_each')?['$content']

After that, click on Add an action -> select Compose action to convert base64 to string, then provide the below information:

base64ToString(outputs('Compose_4'))
How to xml file to Array Microsoft flow

Step 6: Now, click the +New step -> select Append to array variable action. Then provide the below information:

  • Name: Select the variable name.
  • Value: Provide the below information:
{
  "id": @{join(xpath(xml(outputs('Compose_5')), '/product/id/text()'),'')},
  "name": @{join(xpath(xml(outputs('Compose_5')), '/product/name/text()'),'')},
  "description": @{join(xpath(xml(outputs('Compose_5')), '/product/description/text()'),'')},
  "price": @{join(xpath(xml(outputs('Compose_5')), '/product/price/text()'),'')},
  "quantity": @{join(xpath(xml(outputs('Compose_5')), '/product/quantity/text()'),'')}
}
How to xml file to Array using Microsoft flow

Step 7: Now we will use compose action to check the result so, click on the +New step -> select Compose action and then provide the below information:

  • Inputs: Select the variable person details from dynamic content.
How to xml file to Array using Microsoft Power automate

Step 8: Now, to test the flow, click on Save and then click on the Test icon ->select the Manually option -> click on the Test button. Then click Import and select the XML file -> click on Run flow. You can see your flow run successfully.

The XML data is converted to an array in Power Automate.

How to xml file to Array using Power automate

This is how we can convert XML to an array using Power Automate.

Conclusion

In this Power Automate tutorial, we will see how to convert XML to an array using Power Automate.

You may like the following Power Automate tutorials:

>