Parse XML in Power Automate/ Microsoft Flow

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com


The simplest of things are sometimes the sweetest. And here is this one requirement to parse an XML using Power Automate/ Microsoft Flow.

With SOAP giving away to REST based API’s, XML parsing is gradually going out of fashion. But still there are some scenarios where you need to go ahead and do XML parsing. So let’s see how can you do that in Microsoft Flow.


Let’s say you have the following input XML.

<response>
   <status>failure</status>
   <reason>duplicate</reason>
   <recordid>0123456789</recordid>
   <url>https://www.google.com</url>
</response>

What I want is to take a decision based on the status value. So let’s see how I can do this.
Here is the Input Xml.
image
The next step we need is to parse the XML. For that we will use the Compose Action.
In the inputs section, we use this formula – xpath(xml(outputs(‘Input_Xml’)), ‘string(/response/status)’)
image
As you can see in the above step, we are using the xpath formula and then try to parse the status field using the path  – /response/status and then typecasting it to string using the string() construct. Please note that the typecast is necessary. Otherwise the returned results will be an array.


Next we use the Initialize Variable action to set the value from the output of the previous Compose step.
image
And below is the test run.
image
As you can see, we are able to successfully parse the Status field from XML. You can now use the Status field for further processing.

Off-course, the complexity of the XML may vary. But the logic remains same.


Hope this helps!
Debajit Dutta
(Microsoft MVP)