“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.
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!
Take the path, put it in single quotes, and use it as the second parametr in the xpath(…) expression, e.g.
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.
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).
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.