Get an element's value
This article explains how to get the value of a specific element from an existing XML file.
The action to use
Section titled “The action to use”This article uses the “Get XML element value” action.
Details of the “Get XML element value” action
Section titled “Details of the “Get XML element value” action”The action has the following parameters.
| Parameter | Value |
|---|---|
| XML document | The target XML data (must be an XML node object) |
| XPath query | Specify the value to get in XPath format |
| Get value as | Choose from “Text value”, “Numeric value”, “Datetime value”, or “Boolean value”. If you choose anything other than “Text value”, the value is converted to that data type |
| Variables produced | The retrieved value |

When the data has garbled characters
Section titled “When the data has garbled characters”When you read an XML file to create an XML node object, characters may be garbled if the file’s character encoding doesn’t match the “Encoding” setting.
If you see garbled characters, see the following page.
Implement the action
Section titled “Implement the action”Add the sample flow by copying and pasting
Section titled “Add the sample flow by copying and pasting”As a sample, this article uses a flow that saves XML data to a file and then reads one of its values into a separate variable.
The XML is written directly in the flow and has the following structure.
<sample> <data> <content>This is test data</content> </data></sample>Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.
SET FilePath TO $'''C:\\Users\\Public\\Documents\\sample.xml'''XML.WriteXmlToFile.WriteToFileFormatted File: FilePath Xml: $'''<sample><data><content>This is test data</content></data></sample>''' Encoding: XML.FileEncoding.UTF8 Indentation: 2XML.ReadFromFile File: FilePath Encoding: XML.FileEncoding.UTF8 XmlDocument=> XmlDocumentXML.GetXmlElementValue.GetElementValue Document: XmlDocument XPathQuery: $'''/sample/data/content''' TextValue=> XmlElementValueImplement in Power Automate Desktop
Section titled “Implement in Power Automate Desktop”-
In “Search actions”, type “Get XML element value”.
-
Set the parameters as follows.
Parameter Value XML document %XmlDocument% XPath query /sample/data/content Get value as Text value -
When you run the flow, part of the XML data is stored in a variable.
Possible exceptions
Section titled “Possible exceptions”An error occurs if the XPath syntax is wrong or if you specify an invalid XPath.
The “XPath expression returns no element” error occurs when the XPath syntax is correct but the specified XPath doesn’t return an element (for example, when no element matches).
An error also occurs if you specify a data type and the data passed to the action can’t be converted to that data type.
We recommend adding error handling with an “On block error” block.