Written by

Question Yone Moreno · Nov 22, 2023

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:

Property PACPROBLEMAS As %String(MAXLEN = "", XMLNAME = "PAC_PROBLEMAS");

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 &gt;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"

Property PACPROBLEMAS As %String(CONTENT = "ESCAPE", MAXLEN = "", XMLNAME = "PAC_PROBLEMAS");

It stills being the same

📌 Declare ESCAPE = "HTML"

Property PACPROBLEMAS As %String(ESCAPE = "HTML", MAXLEN = "", XMLNAME = "PAC_PROBLEMAS");
It behaves similarly

📌 Declare ESCAPE = "XML"

Property PACPROBLEMAS As %String(ESCAPE = "XML", MAXLEN = "", XMLNAME = "PAC_PROBLEMAS");

It just shows the same behaviour

We have also read:

https://docs.intersystems.com/irisforhealthlatest/csp/documatic/%25CSP…

https://community.intersystems.com/post/convert-string-property-cdata-a…

https://community.intersystems.com/post/there-way-automatically-remove-…

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.

Product version: IRIS 2020.1

Comments

Eduard Lebedyuk · Nov 22, 2023

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&lt;2</PAC_PROBLEMAS></XML>

Documentation.

0
Yone Moreno  Nov 24, 2023 to Eduard Lebedyuk

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:

Property PACPROBLEMAS As %String(CONTENT = "ESCAPE", MAXLEN = "", XMLNAME = "PAC_PROBLEMAS");
 

So then the LOG SOAP shows:

[...]<PAC_PROBLEMAS>46807#278.01#OBESIDAD INFANTIL GRAVE     ( Z-SCORE IMC &gt;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.

0
Eduard Lebedyuk  Nov 24, 2023 to Yone Moreno

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.

0
Krishnaveni Kapu  Jun 14, 2024 to Yone Moreno

Hi ,

Did you get a solution for erasinng  <![CDATA[]]>?

I am having similar issue.

0
Rodolfo Moreira dos Santos · Nov 26, 2023

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 &amp; Test1</FieldInfoEscape>
	<FieldInfoMixed>Written From : 09 , US & Test1</FieldInfoMixed>
</Demo>
0