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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to escape < > char...
Power Automate
Answered

How to escape < > characters

(0) ShareShare
ReportReport
Posted on 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)
  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @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)

     

     

  • Andreff Profile Picture
    9 on at

    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,250 Super User 2025 Season 2 on at

    @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 at

    @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.

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @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 at

    Thank you very much @Deenuji 

     

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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard