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.
|XML Document||Target XML Data (XML Node Object Must be)|
|XPath Query||Specify the value you want to get in the XPath method|
|Acquire a value next||If you specify a non -character string, it will be converted to the specified data type|
|Generated variables||Acquired values|
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.
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.
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
From "Search for action", enter "Get the value of XML elements".
Set the parameter as follows
Parameter name value XML Document % XMLDOCUMENT % XPath Query /sample/data/content Get the value next Text value
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.