Logo
  • Contact form
  • Events & slides
  • Buy me a snack
Logo

Events & slides

Buy me a snack

Contact form

Data privacy policy

About

This blog is made with ♥️ on Notion and made public with Super.so. Rocket icon created by RIkas Dzihab - Flaticon.

RedditLinkedIn
👋🏻
/
📝
All Blogs
/
Learning and working with XML in Power Automate

Learning and working with XML in Power Automate

Table of contents

  • The basics and the structure
  • XML Schema
  • Reading data from a XML document in Power Automate
  • Easiest way
  • Reading simple XML documents
  • Reading list type XML documents
  • Transforming a XML list into an JSON array
  • Further examples
  • Summing up an array of numbers
  • Changelog
☝
TL;DR - Some legacy or older systems might still use XML to return data to you when connecting to their API. As XML ist still around and you can work with it in Power Automate, this article will explain the basics including the use of xml() and xpath().

The basics and the structure

Just like JSON, XML describes information or represents data. More on XML here: https://www.w3schools.com/xml/default.asp Power Automate supports all XMLs in Version 1.

Official links:

  • https://learn.microsoft.com/en-us/azure/logic-apps/expression-functions-reference#xpath
  • https://learn.microsoft.com/en-us/azure/logic-apps/expression-functions-reference#xml

XML Schema

Overall XML follows this syntax:

<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>

To write a valid XML schema, you need to follow some rules:

  1. The XML can start with a prolog, but this is optional
<?xml version="1.0" encoding="UTF-8"?>
  1. Just like JSON the names of the roots or childs can vary on your use case. In the example on the right, the root element is bookstore and the next child is book. In one XML document you might even find multiple different structures for different data.
  2. Every XML document must have a root element (bookstore)
  3. XML elements must have a closing tag (message and /message)
<message>This is correct</message>
  1. XML tags are case sensitive
  2. XML attribute values must be quoted (e.g. book category=”web”)

Example XML

image

Reading data from a XML document in Power Automate

💡

Before you try to parse XML in Power Automate, you should always use the expression xml() to format a stringified” XML document into readable xml. Then you use the expression xpath() to navigate through the XML document.

Easiest way

The expression json() can work with string or xml files. In case of XML files the expression will transform the xml into a JSON.

json(xml(outputs('Compose_-_XML_simple')))
⚠️

Be aware that it will only translate what the XML shows. For example: Situation 1: You have a XML where one child element only holds one further child. Json() will identify this as an object. Situation 2: The same XML now has two children in that child element, json() will identify is as an array. This might break your flow.

Check out the other options below.

Reading simple XML documents

I would describe a simple XML document as a single entity information or anything that is not a list. The EmployeeProfile is the returned data from an API

Reading the Employee Id value: EMP-1001

✅

string() lets us read the value of the element that we have built the path for.

xpath(xml(outputs('Compose_-_XML_simple')), 'string(/EmployeeProfile/EmployeeId)')

Reading the Department value: IT

xpath(xml(outputs('Compose_-_XML_simple')), 'string(/EmployeeProfile/Department)')

Reading the currency attribute value of the salary

✅

@ in front of the attributes name is needed to get the value of an attribute.

xpath(xml(outputs('Compose_-_XML_simple')), 'string(/EmployeeProfile/Salary/@currency)')

In my example the XML document is stored in an compose action called “Compose - xml simple”.

image

Example XML

💡

Using only one slash to navigate along a path, tells the xpath() an absolute path. Using double slashs allows the xpath() to freely the element from within the complete xml document. This might lead to confusing if a elements name is reused.

Reading list type XML documents

List type XML documents can be the equivalent of JSON arrays - they are a list of information. In my example the XML document is stored in an compose action called “Compose - xml advanced”.

image
‣
Example XML

Transforming a XML list into an JSON array

Yes, you can transform a XML list into a cleaner JSON array by using the select action. It requires you to manually map out each element and its value. You can have AI do it with all elements when you give it one example.

From: xpath(
		xml(outputs('Compose_-_xml_advanced')),
    '/Employees/EmployeeProfile'
)
Map Left: EmployeeId
Map Right: xpath(item(),'string(/EmployeeProfile/EmployeeId)')
✅

As an expression for from, we use the Employees node. It basically already looks like an JSON array. We then map the elements name to its value by using the already know item() syntax. We only add the part that reads the current items EmployeeId using string().

In Power Automate it looks like this:

image

The raw outputs of the select action show this result:

image

Lets add the salary and currency to our select action. We always want to apply the correct data type for our information. This mean that the salary should be an integer value in our array.

For the salary you can either wrap the xpath() expression with int() or float(). Either expression works and should be picked based on your use case.

From: xpath(
		xml(outputs('Compose_-_xml_advanced')),
    '/Employees/EmployeeProfile'
)
Map Left: Salary
Map Right: float(xpath(item(),'string(/EmployeeProfile/Salary)'))

For the currency:

From: xpath(
		xml(outputs('Compose_-_xml_advanced')),
    '/Employees/EmployeeProfile'
)
Map Left: Currency
Map Right: xpath(item(),'string(/EmployeeProfile/Salary/@currency)')

In Power Automate it looks like this:

image

The raw outputs of the select action show this result:

image
💡

Afterwards, any filtering, sorting or looping can than be done using basic Power Automate features.

Further examples

Summing up an array of numbers

In this example I wanted to sum up all the meeting durations for one day from my outlook calendar. I used a select action to return the duration in hours, then a compose action to transform into a json array. Then that array gets transformed using xpath where the numbers are summed up.

//Select action value (no mapping)
div(
    float(
      sub(
        ticks(item()?['end']),ticks(item()?['start'])
      )
    ),36000000000
)

//Compose action 1
{
  "root": {
    "Numbers": body('Select')
  }
}

//Compose action 2 - result is the summed numbers
xpath(xml(outputs('Compose_-_1')), 'sum(/root/Numbers)')

Changelog

Date
Changes
03.03.2026
Initial version
31.03.2026
Converting XML to JSON using json() expression

❤️ Thanks for reading.

<EmployeeProfile status="Active">
    <EmployeeId>EMP-1001</EmployeeId>
    <FirstName>Anna</FirstName>
    <LastName>Schmidt</LastName>
    <Department>IT</Department>
    <JobTitle>Cloud Consultant</JobTitle>
    <Email>anna.schmidt@contoso.com</Email>
    <Phone>+49 30 123456</Phone>
    <HireDate>2022-04-01</HireDate>
    <Salary currency="EUR">75000</Salary>
    <Manager>
        <ManagerId>EMP-1000</ManagerId>
        <ManagerName>Michael Bauer</ManagerName>
    </Manager>
</EmployeeProfile>
<Employees>
    <EmployeeProfile status="Active">
        <EmployeeId>EMP-1001</EmployeeId>
        <FirstName>Anna</FirstName>
        <LastName>Schmidt</LastName>
        <Department>IT</Department>
        <JobTitle>Cloud Consultant</JobTitle>
        <Email>anna.schmidt@contoso.com</Email>
        <Phone>+49 30 123456</Phone>
        <HireDate>2022-04-01</HireDate>
        <Salary currency="EUR">75000</Salary>
        <Manager>
            <ManagerId>EMP-1000</ManagerId>
            <ManagerName>Michael Bauer</ManagerName>
        </Manager>
    </EmployeeProfile>
    <EmployeeProfile status="Inactive">
        <EmployeeId>EMP-1002</EmployeeId>
        <FirstName>Peter</FirstName>
        <LastName>Neumann</LastName>
        <Department>Finance</Department>
        <JobTitle>Financial Analyst</JobTitle>
        <Email>peter.neumann@contoso.com</Email>
        <Phone>+49 40 654321</Phone>
        <HireDate>2019-07-15</HireDate>
        <Salary currency="EUR">65000</Salary>
        <Manager>
            <ManagerId>EMP-1005</ManagerId>
            <ManagerName>Laura Fischer</ManagerName>
        </Manager>
    </EmployeeProfile>
    <EmployeeProfile status="Active">
        <EmployeeId>EMP-1003</EmployeeId>
        <FirstName>Maria</FirstName>
        <LastName>Lopez</LastName>
        <Department>Marketing</Department>
        <JobTitle>Marketing Specialist</JobTitle>
        <Email>maria.lopez@contoso.com</Email>
        <Phone>+49 69 789012</Phone>
        <HireDate>2021-02-10</HireDate>
        <Salary currency="EUR">58000</Salary>
        <Manager>
            <ManagerId>EMP-1010</ManagerId>
            <ManagerName>Stefan Meier</ManagerName>
        </Manager>
    </EmployeeProfile>
</Employees>