XML Automation in Power Automate Desktop

XML stands for Extensible Markup Language which is used to describe the data. The main purpose of XML is structuring the data. XML makes it easy for the computer to generate data, read data and ensure that the data structure is unambiguous.
XML actions are used to manage and manipulate XML files. For example, we have an XML file here named XML_Auto.xml. In that, we have catalog as node and book as a child.

Under XML we have so many XML actions listed.

- Read XML from file : This action reads XML contents file into a new variable
- Write XML to file : This action writes the content of an XML node variable into a file.
- Get XML element attribute : This action gets the value of an attribute of an XML element.
- Get XML element value : This action is used to get the value of the XML element.
- Set XML element attribute : This action set the value of an attribute of an XML element
- Set XML element value : This action is used to Set the value of an XML element.
- Remove XML element : This action is used to remove one or more XML elements from an XML file.
- Remove XML element attribute : This action removes an attribute from an XML element.
- Insert XML element : This action inserts a new XML element into an XML file.
- Execute XPath Expression : This action extracts values or data from an XML file with the help of a provided XPath query.
PDF Automation in Power Automate Desktop
Creating a flow with XML actions
- Open Power Automate Desktop App.

- Firstly, we need to create a flow. Click on New flow.

- Create a flow name xml-automation in Power Automate Desktop.

Email Automation in Power Automate Desktop
This action reads XML contents file into a new variable
- From the Actions panel, drag and drop the Read XML from file action into the workspace. Add File path of the XML file and Encoding as Default. The output will be produced in the XmlDocument variable. Click on Save.

- Save and Run the flow. We get output as the contents from an XML file into the XmlDocument variable.

Variables in Power Automate Desktop
This action extracts values or data from an XML file with the help of a provided XPath query.
- Here, we are going to provide an XPath of <price>. To do so we need to provide an XPath query to perform the action.

- From the Actions panel, drag and drop the Execute XPath expression action into the workspace. Add XPath query as catalog/bookstore/book/price.
- The output will be produced in the XPathResults variable. Click on Save.

- Save and Run the flow. We get output as the price value into the XPathResults variable.

File Actions in Power Automate Desktop
Get XML attribute values
This action gets the value of an attribute of an XML element.
- Here, we are going to get the attribute from "lang" under the "title" element.

- From the Actions panel, drag and drop the Get XML element attribute action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/title. Add Attribute name as lang and get value as a Text value.
- The output will be produced in the XmlAttributeValue variable. Click on Save.

- Save and Run the flow. We get output as the eng attribute into the XmlAttributeValue variable.

PDF Automation in Power Automate Desktop
Set XML Element Attribute in Power Automate Desktop
This action set the value of an attribute of an XML element
- From the Actions panel, drag and drop the Set XML element attribute action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/title. Add Attribute name as lang and value as Spanish. Click on Save.

- Save and Run the flow. We get output as the attribute "lang" set to value "Spanish" into the XmlDocument variable.

- To add a new attribute edit the Set XML element attribute action. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/title. Add Attribute name as class and value as A. Click on Save.

- Save and Run the flow. We get output as the new attribute "class" set to value as "A" into the XmlDocument variable.

OCR Actions in Power Automate Desktop
Remove XML Element Attribute
This action removes an attribute from an XML element.
- From the Actions panel, drag and drop the Remove XML element attribute action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/title with attribute name "lang". Click on Save.

- Save and Run the flow. We get the output without the "lang" attribute in the "title" element into the XmlDocument variable.

List Variable in Power Automate Desktop
Insert XML Element
This action inserts a new XML element into an XML file.
- From the Actions panel, drag and drop the Insert XML element action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book. Add XML element to insert as <genre>. Click on Save.

- Save and Run the flow. We get output as the new element inserted as <genre> into the XmlDocument variable.

Mouse and Keyboard in Power Automate Desktop
Get XML Element in Power Automate Desktop
This action is used to get the value of the XML element.
- Here, we want to take the value of element <title>.

- From the Actions panel, drag and drop the Get XML element value action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/title. Get value as a Text value.
- The output will be produced in the XmlElementValue variable. Click on Save.

- Save and Run the flow. We get output as the Harry Potter as value into the XmlElementValue variable.

Wait in Power Automate Desktop
Set XML Element Value
This action is used to Set the value of an XML element.
- From the Actions panel, drag and drop the Set XML element value action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/title. Add XML element value as "Wings Of Fire". Click on Save.

- Save and Run the flow. We get output as the element "title" set to value as "Wings Of Fire" into the XmlDocument variable.

Folder Actions in Power Automate Desktop
Remove XML Element
This action is used to remove one or more XML elements from an XML file.
- From the Actions panel, drag and drop the Remove XML element action into the workspace. Add XML document as XmlDocument variable and add XPath query as catalog/bookstore/book/price. Click on Save.

- Save and Run the flow. We get the output without the "price" element into the XmlDocument variable.

Switch Case in Power Automate Desktop
This action writes the content of an XML node variable into a file.
- From the Actions panel, drag and drop the Write XML to file action into the workspace. Add File path where you want to save the contents. Add XmlDocument variable to XML to write.
- Select Encoding as Default, enable XML Format, and set Indentation per level as 5. Click on Save.

- Save and Run the flow. We get output as the XML contents written into Books.txt as text file.

Compression Action in Power Automate Desktop
About Author :I am Sharvari Raut, having sound knowledge and experience in technical writing. Currently, pursuing my B.Tech in Computer Science and Engineering.