Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
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.


🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

3 thoughts on “How to extract value from XML using Power Automate flow”

  1. powerautomate123 says:
    June 16, 2022 at 1:49 pm

    am using two separated compose actions in order to use this XPATH expression:

    compose 1: xpath(xml(outputs(‘Get_file_content_compose’)),’//invoicenumber[1]/text()’)

    compose 2: xpath(xml(outputs(‘Get_file_content_compose’)),’//invoiceamount[1]/text()’)

    Since i am doing this in two separated compose actions i am not able to add this in one row, at the moment it is reflecting as two excel rows.

    Can anyone please advise how to make one xpath expression to extract ‘invoicenumber’ and ‘invoiceamount’ ?

    and if i use 1 xpath expression instead of 2, will i be able to update and view in one excel row instead of 2?

    Reply
    1. Tom says:
      June 22, 2022 at 8:56 pm

      Hello powerautomate123,
      you can use both of the expression in a single ‘Compose’ action and store the data as an object:
      {
      “InvoiceNumber”: “xpath(xml(outputs(‘Get_file_content_compose’)),’//invoicenumber[1]/text()’)”,
      “InvoiceAmount”: “xpath(xml(outputs(‘Get_file_content_compose’)),’//invoiceamount[1]/text()’)”
      }

      Reply
  2. Pingback: Automatic Code Review of Power Automate Flows with Power Platform Pipelines – Automate The Mundane

Leave a Reply Cancel reply

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

🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundle—everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes