web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : 976mYAINun+6KexPUE6Vez
Power Automate - Power Automate Desktop
Answered

How to escape < > characters

Like (0) ShareShare
ReportReport
Posted on 13 May 2024 15:04:33 by 9

Hello,

 

I've been beating my head with this for hours searching and testing different aproaches with no luck so far.

 

I'm doing a flow in PAD where I read and change some values in a XML file.

 

I want fo set a XML element value but that value has to be in CDATA format so I the value I need to set is <![CDATA[value]]>. When I write the file Power Automate replaces the <> characters with unicode values and the value writes as &lt;![CDATA[2222222]]&gt; and then the XML passes as invalid.

 

I tried to escape the <> using diferent methods but none of them work and I didn't find any other solutions to be able do set this characters.

 

Did someone came across this issue?

 

Thank you in advance

I have the same question (0)
  • Andreff Profile Picture
    9 on 13 May 2024 at 17:02:53
    Re: How to escape < > characters

    Thank you very much @Deenuji 

     

    I was able to use your solution and it works like a charm. 🙂

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,206 Super User 2025 Season 2 on 13 May 2024 at 16:19:24
    Re: How to escape < > characters

    @Andreff 

     

    Got it. The problem arises because "<" and ">" are reserved characters in XML, which means that when you attempt to use them directly, they get converted into entities.

    Please refer the below link for more details - Using Reserved Characters (<, >, &, ', and ") Inside Elements (revenera.com)

    How to handle this issue?

    We can supply the XML value as text and substitute the occurrences of "&lt;" and "&get;" with "<" and ">".

     

    Here's the suggested approach:

     

    You can assign the CData value to your XML and utilize the "replace text" option to swap characters with "<" and ">". If you wish to persist the modified data as an XML node, then write that text as XML file then  you can subsequently read that file and store the data as an XML node for further processing.

     

    Deenuji_0-1715616834989.png

     

    Code:

     

    XML.ReadFromFile File: $'''C:\\Boot\\XMLDATA.xml''' Encoding: XML.FileEncoding.DefaultEncoding XmlDocument=> XmlDocument
    XML.SetElementValue Document: XmlDocument XPathQuery: $'''/sample/order_carrier/tracking_number''' ElementValue: $'''<![CDATA[22222]]>'''
    Text.Replace Text: XmlDocument.InnerXML TextToFind: $'''&lt;''' IsRegEx: False IgnoreCase: False ReplaceWith: $'''<''' ActivateEscapeSequences: False Result=> Replaced
    Text.Replace Text: Replaced TextToFind: $'''&gt;''' IsRegEx: False IgnoreCase: False ReplaceWith: $'''>''' ActivateEscapeSequences: False Result=> Replaced
    File.WriteText File: $'''C:\\Boot\\XMLdocument.XML''' TextToWrite: Replaced AppendNewLine: False IfFileExists: File.IfFileExists.Overwrite Encoding: File.FileEncoding.DefaultEncoding
    XML.ReadFromFile File: $'''C:\\Boot\\XMLdocument.XML''' Encoding: XML.FileEncoding.DefaultEncoding XmlDocument=> XmlDocument

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

  • Andreff Profile Picture
    9 on 13 May 2024 at 15:41:54
    Re: How to escape < > characters

    @Deenuji 

     

    This is what I'm getting first:

    <?xml version="1.0" encoding="UTF-8"?>
    <sample xmlns:xlink="http://www.w3.org/1999/xlink">
     <order_carrier>
     <id><![CDATA[160]]></id>
     <id_order><![CDATA[160]]></id_order>
     <id_carrier><![CDATA[32]]></id_carrier>
     <id_order_invoice><![CDATA[0]]></id_order_invoice>
     <weight><![CDATA[0.000000]]></weight>
     <shipping_cost_tax_excl><![CDATA[3.170000]]></shipping_cost_tax_excl>
     <shipping_cost_tax_incl><![CDATA[3.900000]]></shipping_cost_tax_incl>
     <tracking_number></tracking_number>
     <date_add><![CDATA[2022-10-03 17:18:48]]></date_add>
     </order_carrier>
    </sample>

     

    And this is the result after setting the value:

    <?xml version="1.0" encoding="UTF-8"?>
    <sample xmlns:xlink="http://www.w3.org/1999/xlink">
     <order_carrier>
     <id><![CDATA[160]]></id>
     <id_order><![CDATA[160]]></id_order>
     <id_carrier><![CDATA[32]]></id_carrier>
     <id_order_invoice><![CDATA[0]]></id_order_invoice>
     <weight><![CDATA[0.000000]]></weight>
     <shipping_cost_tax_excl><![CDATA[3.170000]]></shipping_cost_tax_excl>
     <shipping_cost_tax_incl><![CDATA[3.900000]]></shipping_cost_tax_incl>
     <tracking_number>&lt;![CDATA[2222222]]&gt;</tracking_number>
     <date_add><![CDATA[2022-10-03 17:18:48]]></date_add>
     </order_carrier>
    </sample>

    As you can see the "tracking_number" is getting the value altered but the <> is changed in PAD.

  • Deenuji_Loganathan_ Profile Picture
    6,206 Super User 2025 Season 2 on 13 May 2024 at 15:34:24
    Re: How to escape < > characters

    @Andreff 

     

    This looks fine, Please share some sample XML data which you got from webservice call. I want to understand the existing structure of your XML data

     

     

  • Andreff Profile Picture
    9 on 13 May 2024 at 15:30:42
    Re: How to escape < > characters

    Hi @Deenuji 

     

    Here it goes. 

     

    I don't have the PAD in english but basically I'm writing an XML file, reading it, then setting the value and writing again the file.

     

    Thank you

  • Deenuji_Loganathan_ Profile Picture
    6,206 Super User 2025 Season 2 on 13 May 2024 at 15:13:26
    Re: How to escape < > characters

    @Andreff 

     

    To understand your use case deeper, could you please share screenshot of your desktop flow pls? Include some sample XML document(before inserting the value)

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 707 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 499 Moderator

#3
chiaraalina Profile Picture

chiaraalina 312

Last 30 days Overall leaderboard
Loading complete