XML Automation in Power Automate Desktop

logo-xml-automation-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.
example-xml-automation-power-automate-desktop

Under XML we have so many XML actions listed.
actions-xml-automation-power-automate-desktop

  • 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.
    desktop-app-power-automate-desktop
  • Firstly, we need to create a flow. Click on New flow.
    new-flow-layout-power-automate-desktop
  • Create a flow name xml-automation in Power Automate Desktop.
    new-flow-xml-automation-power-automate-desktop

Email Automation in Power Automate Desktop

Read XML from file 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.
    read-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the contents from an XML file into the XmlDocument variable.
    read-result-xml-automation-power-automate-desktop

Variables in Power Automate Desktop

Execute XPath Expression 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.
    initial-xpath-xml-automation-power-automate-desktop
  • 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.
    xpath-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the price value into the XPathResults variable.
    result-xpath-xml-automation-power-automate-desktop

File Actions in Power Automate Desktop

XML Attributes 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.
    initial-get-xml-element-attribute-xml-automation-power-automate-desktop
  • 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.
    get-xml-element-attribute-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the eng attribute into the XmlAttributeValue variable.
    result-get-xml-element-attribute-xml-automation-power-automate-desktop

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.
    set-xml-element-attribute-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the attribute "lang" set to value "Spanish" into the XmlDocument variable.
    result-set-xml-element-attribute-xml-automation-power-automate-desktop
  • 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.
    set2-xml-element-attribute-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the new attribute "class" set to value as "A" into the XmlDocument variable.
    result-set2-xml-element-attribute-xml-automation-power-automate-desktop

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.
    remove-xml-element-attribute-xml-automation-power-automate-desktop
  • Save and Run the flow. We get the output without the "lang" attribute in the "title" element into the XmlDocument variable.
    result-remove-xml-element-attribute-xml-automation-power-automate-desktop

List Variable in Power Automate Desktop

XML Element Actions

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.
    insert-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the new element inserted as <genre> into the XmlDocument variable.
    result-insert-xml-automation-power-automate-desktop

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>.
    initial-get-xml-element-value-xml-automation-power-automate-desktop
  • 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.
    get-xml-element-value-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the Harry Potter as value into the XmlElementValue variable.
    result-get-xml-element-value-xml-automation-power-automate-desktop

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.
    set-xml-element-value-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the element "title" set to value as "Wings Of Fire" into the XmlDocument variable.
    result-set-xml-element-value-xml-automation-power-automate-desktop

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.
    remove-xml-element-xml-automation-power-automate-desktop
  • Save and Run the flow. We get the output without the "price" element into the XmlDocument variable.
    result-remove-xml-element-xml-automation-power-automate-desktop

Switch Case in Power Automate Desktop

Write XML to file

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.
    write-xml-element-attribute-xml-automation-power-automate-desktop
  • Save and Run the flow. We get output as the XML contents written into Books.txt as text file.
    result-write-xml-element-attribute-xml-automation-power-automate-desktop

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.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions