Handling CDATA in XML Responses: Removing <![CDATA[]]> in String Properties for Clean Integration
Hello,
First of all thanks for your help.
We have the following scenario: some responses include special characters as ">" and "<" which are being put inside a property defined as:
So then, when we observe the LOG SOAP it shows that the Target System replies to the ESB as follows:
➡️ <PAC_PROBLEMAS>46807#278.01#OBESIDAD INFANTIL GRAVE ( Z-SCORE IMC >2,70 ) #19/09/2019##N#</PAC_PROBLEMAS>
However when we observe the Visual Trace, the message being replied from the Operation to the Process has a CDATA section as you could see:
➡️ <s01:PAC_PROBLEMAS><![CDATA[46807#278.01#OBESIDAD INFANTIL GRAVE ( Z-SCORE IMC >2,70 )#19/09/2019##N#S]]>
</s01:PAC_PROBLEMAS>
We do need to find a way to remove the <![CDATA[]]> because the system which receives the response needs it to be raw without any CDATA.
We do have checked that it only shows this behaviour with special character which conflict with the ones that are used in XML as ">" and "<".
We do have investigated the following options:
📌 Declare CONTENT = "ESCAPE"
It stills being the same
📌 Declare ESCAPE = "HTML"
It behaves similarly
📌 Declare ESCAPE = "XML"
It just shows the same behaviour
We have also read:
https://docs.intersystems.com/irisforhealthlatest/csp/documatic/%25CSP.D...
https://community.intersystems.com/post/convert-string-property-cdata-an...
https://community.intersystems.com/post/there-way-automatically-remove-s...
However the previous post does not cover this topic.
Could you help us please?
🔎 How could we remove <![CDATA[]]> in a String property? 📍
Could we declare there any properties, parameters, configurations or options to remove it?
What is the most recommended and clean way to achieve this?
Thanks for your help, time, answers, teaching and support.
You need CONTENT=ESCAPE instead of CONTENT=STRING. Here's an example:
Class Utils.XML Extends (%RegisteredObject, %XML.Adaptor) { Property PACPROBLEMAS As %String(CONTENT = "ESCAPE", MAXLEN = "", XMLNAME = "PAC_PROBLEMAS"); /// do ##class(Utils.XML).Test() ClassMethod Test() { set obj = ..%New() set obj.PACPROBLEMAS = "1<2" do obj.XMLExportToString(.xml) zw xml } }
Produces:
<XML><PAC_PROBLEMAS>1<2</PAC_PROBLEMAS></XML>
Documentation.
Thanks @Eduard Lebedyuk for your reply and example.
We have checked and your example does convert the "<" to "%lt;" .
However when at our integration we have followed your suggestions:
So then the LOG SOAP shows:
[...]<PAC_PROBLEMAS>46807#278.01#OBESIDAD INFANTIL GRAVE ( Z-SCORE IMC >2,70 )#19/09/2019##N#S</PAC_PROBLEMAS>[...]
However when the Visual Trace shows this content, it spawns a CDATA which we do not understand how to remove:
<s01:PAC_PROBLEMAS><![CDATA[46807#278.01#OBESIDAD INFANTIL GRAVE ( Z-SCORE IMC >2,70 )#19/09/2019##N#S]]>
</s01:PAC_PROBLEMAS>
Is there any configuration, parameter, property or addon which we could employ inside the Web Service Client, the SOAP Operation, the Ens.Response Message, or the inner Data Structures where we could express that we need to erase <![CDATA[]]>?
How could we achieve this?
Thanks for your time, help and support. We are grateful for your reply.
Is CDATA actually getting sent or is it just a visualization issue?
I suppose you can use HS Trace operation or IO logging to get the raw output.
Hi ,
Did you get a solution for erasinng <![CDATA[]]>?
I am having similar issue.
Class example
Class Test.XmlContent Extends (%RegisteredObject, %XML.Adaptor) { Parameter XMLNAME = "Demo"; Property FieldInfoString As %String(MAXLEN = ""); Property FieldInfoEscape As %String(CONTENT = "ESCAPE", MAXLEN = ""); Property FieldInfoMixed As %String(CONTENT = "MIXED", MAXLEN = ""); }
Execution example
Set t = ##class(Test.XmlContent).%New() Set t.FieldInfoString = "Written From : 09 , US & Test1" Set t.FieldInfoEscape = "Written From : 09 , US & Test1" Set t.FieldInfoMixed = "Written From : 09 , US & Test1" Do t.XMLExportToString(.String)
Output
<Demo> <FieldInfoString><![CDATA[Written From : 09 , US & Test1]]></FieldInfoString> <FieldInfoEscape>Written From : 09 , US & Test1</FieldInfoEscape> <FieldInfoMixed>Written From : 09 , US & Test1</FieldInfoMixed> </Demo>