Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

How to extract value from XML using Power Automate flow

Posted on May 8, 2022May 8, 2022 by Tom

“Is it possible to extract a specific value from an XML using Power Automate flow? What’s the best approach to do that?”


When you build flows in Power Automate, you’re working with JSON. That’s the format on the background, it’s easy to work with, and you can extract any value using an expression. But there’s another format that you can encounter when connecting to other systems, and that’s an XML. The formats are quite similar, you can easily convert JSON into XML, but not the other way around. And as such it’s a bit harder to extract the values. How do you then extract a specific value from an XML?

Use the xpath(…) expression

If you’ve got an XML, you can use the xpath(…) expression to find a specific value. It’s the same expression as used to extract values from SP multiple people picker column, but this time it’s a bit simpler.

xpath(<xml>, <path>)

Note: <…> are placeholders, replace them including < and >.

You already have an XML so you can apply the expression directly on the data. Let’s take the example XML below:

<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

…and the value to extract is in the <body>. You could build the <path> manually, but there’re many tools that can do it for you, e.g. the xpather. Copy/paste your XML and while holding ctrl/cmd hover on the desired value. It’ll return the path leading to the value which can be used in the expression.

Note: since it’s a public website you should replace all potentially sensitive data in your XML with some placeholders before you paste it!

Power Automate extract value xml

Take the path, put it in single quotes, and use it as the second parametr in the xpath(…) expression, e.g.

xpath(xml(outputs('Compose_-_XML')),'//body[1]/text()[1]')

If you encounter the error message “The template language function ‘xpath’ expects its first parameter to be an XML object”, add also the xml(…) expression as shown above.

Power Automate extract value xml

The expression will return all elements at the defined path in the xml as an array. The last step could be to turn them into a string with the join(…) expression, e.g. separated by comma (if there’re move values).

join(outputs('Compose_-_value_from_xml'),', ')

Summary

When you work with an XML in Power Automate, it’s much easier to use the xpath(…) expression to extract a specific value than trying to somehow parse it. It might look complicated on the first look, but with the available services like the xpather it’s easy to build the path and use it in the expression.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

NOW AVAILABLE:

The Ultimate Power Automate expressions cheat sheet
Spend your time thinking about what the flow should do, not how to do it!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • How to create a new SharePoint list column with Power Automate flowMay 22, 2022
  • How to combine expressions in your Power Automate flowsMay 18, 2022
  • Import Planner tasks with checklists into various buckets (Power Automate)May 15, 2022
  • How to get notified when Planner task was reassigned (Power Automate)May 11, 2022
  • How to extract value from XML using Power Automate flowMay 8, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme