Skip to main content

File output

This time, I will explain how to write the XML format data acquired and created in the file.

Action to use

This time, I use the action "Write XML to the file".

"Write XML to the file" Action details

The action has the following parameters.

Parameter namevalue
File PathFile name of writing (if not existed)
Writing XMLWriting XML Data
EncodingCharacter code that outputs XML data
Format setting XMLCheck when formatting the writing data
Indent for each levelNumber of spaces indenting nested nodes

action

Supplement to encoding

For encoding, selection may cause garbled characters.

In order to be displayed in Windows notepad, we recommend that you select "ANSI", and "UTF-8" to reuse the output XML data.

Implementing action

Add a sample flow with copy and paste

This time, as a sample, we obtained Google's site map information (XML) and prepared a flow to write in the file.

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

Web.InvokeWebService.InvokeWebService Url: $'''https://www.google.com/sitemap.xml''' Method: Web.Method.Get Accept: $'''application/xml''' ContentType: $'''application/xml''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: False EncodeRequestBody: True UserAgent: $'''Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20100312 Firefox/3.6''' Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False Response=> WebServiceResponse StatusCode=> StatusCode
IF StatusCode <> 200 THEN
EXIT Code: 0 ErrorMessage: $'''The process was interrupted because the acquisition of XML data failed.'''
END
XML.WriteXmlToFile.WriteToFileFormatted File: $'''C:\\Users\\Public\\Documents\\google-sitemap.xml''' Xml: WebServiceResponse Encoding: XML.FileEncoding.DefaultEncoding Indentation: 2

Operate and implement Power Automate Desktop

  1. From "Search for action", enter "Write XML to the file".

  2. Set the parameter as follows

    Parameter namevalue
    File PathC:\Users\Public\Documents\created-by-pad.xml
    Write down XML<?xml version="1.0" encoding="UTF-8"?><sample>This is a sample data</sample>
    EncodingUTF-8
    Formatting XMLcheck
    Indent for each level2
  3. When executed, XML data is output to the target file path.

The text value specified as the XML data is described in one line, but by checking the format setting, the line breaks and indents are inserted at the appropriate position.

The exception that can occur

If the specified file path is not appropriate, an error may occur, and an error occurs when writing in XML.

We recommend that you implement block processing.