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 <![CDATA[2222222]]> 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
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 "<" 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.
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: $'''<''' IsRegEx: False IgnoreCase: False ReplaceWith: $'''<''' ActivateEscapeSequences: False Result=> Replaced
Text.Replace Text: Replaced TextToFind: $'''>''' 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 🚀
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><![CDATA[2222222]]></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.
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
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
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)
Michael E. Gernaey
497
Super User 2025 Season 2
David_MA
436
Super User 2025 Season 2
Riyaz_riz11
244
Super User 2025 Season 2