Skip to main content

Acquisition of element value

This time, we will explain the value of a specific element from the existing XML file.

Action to use

This time, the action to use is "acquire the value of the XML element".

"Get the value of the XML element" action details

The action has the following parameters.

Parameter namevalue
XML DocumentTarget XML Data (XML Node Object Must be)
XPath QuerySpecify the value you want to get in the XPath method
Acquire a value nextIf you specify a non -character string, it will be converted to the specified data type
Generated variablesAcquired values

action

When the data is garbled

When creating an XML node object, it may cause garbled characters in some cases.

If you are garbled, please refer to the following page.

Implementing action

Add a sample flow with copy and paste

This time, as a sample, we have prepared a flow to save XML data in a file and then get some values as a different variable.

XML is described directly and has the following structure.

<sample>
<data>
<content>Test data</content>
</data>
</sample>

Copy the following code and paste it on the edit screen of Power Automate Desktop to add the target action.

SET FilePath TO $'''C:\\Users\\Public\\Documents\\sample.xml'''
XML.WriteXmlToFile.WriteToFileFormatted File: FilePath Xml: $'''<sample><data><content>Test data</content></data></sample>''' Encoding: XML.FileEncoding.UTF8 Indentation: 2
XML.ReadFromFile File: FilePath Encoding: XML.FileEncoding.UTF8 XmlDocument=> XmlDocument
XML.GetXmlElementValue.GetElementValue Document: XmlDocument XPathQuery: $'''/sample/data/content''' TextValue=> XmlElementValue

Power Automate Desktop is implemented

  1. From "Search for action", enter "Get the value of XML elements".

  2. Set the parameter as follows

    Parameter namevalue
    XML Document% XMLDOCUMENT %
    XPath Query/sample/data/content
    Get the value nextText value
  3. By execution, a part of the XML data is stored in the variable.

The exception that can occur

If the XPath format is incorrect or an invalid XPath is specified, an error will occur.

If an error "XPath type does not return the element", there is no error in the format, but if the specified destination does not return the value (only for child elements), it will be an error.

In addition, if the data type is specified, an error will also occur when data that cannot be converted correctly to the data type is passed.

We recommend that you implement block processing.