Working with CDATA inside your BusinessWorks Process

One of the most misterious things when you are working with your TIBCO BusinessWorks software is how to handle the CDATA sections inside the XML you are transforming in the BW process.

The CDATA section are special XML sections when you can use unescaped text (like XML tags or similar) as a XML tag value, as you can see here:

<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
  {
  return 1;
  }
else
  {
  return 0;
  }
}
]]>
</script>

If you want to increase your knowledge about this sections, please visit this link: Link

The main problem you could be facing when you are trying to use this kind of section in BW is that the software always try to scape this kind of values and it not check if it is a CDATA section or something special. It always treats the value as a normal string value and it executes the ‘escape process’.

If you have a simple process with only a Mapper activity and a Render XML activity to get an XML value of your XML tree object, you can see the CDATA content is going to be escapen without your ‘permission’ :), as you can see here:

CDATA_1

(Process CDATANormalError.process)

2014 Nov 04 22:16:04:868 GMT +0100 BW.CDATA User [BW-User] - Job-2000 [CDATANormalError.process/Log]: <?xml version="1.0" encoding="UTF-8"?>
<root>
 <param>
&lt;insideroot&gt;insidevalue&lt;/insideroot&gt;
</param>
</root>

Ok, If we only want to log a CDATA or persist it inside a file, there is no problem, because you could use the configuration available inside the Render XML activity as you can see here:

CDATA_2

After this configuration you get this output in your Designer console:

[CDATAEscapedRenderXML.process/Log]: <?xml version="1.0" encoding="UTF-8"?>
<ns0:root xmlns:ns0="http://www.tibco.com/schemas/CDATA/Schema.xsd">
 <ns0:param><![CDATA[<insideroot>insidevalue</insideroot>]]></ns0:param>
</ns0:root>

You must think: “Ok, it’s a little bit tricky but that’s all. We have reach our goal” but that’s not true, because if we want to use the CDATA section inside an SOAP Request/Reply we’ve facing a more difficult problem.

Because you will be getting something like this:

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><ns0:operationRequest xmlns:ns0="http://www.example.org/schema/1401564634082"><in xmlns="">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ns0:root xmlns:ns0="http://www.tibco.com/schemas/CDATA/Schema.xsd"&gt;
 &lt;ns0:param&gt;&lt;![CDATA[&lt;insideroot&gt;insidevalue&lt;/insideroot&gt;]]&gt;&lt;/ns0:param&gt;
&lt;/ns0:root&gt;</in></ns0:operationRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>

This problem is still unsolved for us, so if you have some thoughts or help, please, leave a comment!!!!!

Advertisements

3 thoughts on “Working with CDATA inside your BusinessWorks Process

  1. I’ve found working with cdata in BW to be a challenge for sure. Not sure if this helps, but I had to recently parse data coming in from another application that had a cdata section. Basically the structure was:

    — long cdata string here

    I needed to parse the string in the metadata element using the Parse XML activity, but it was treating the CDATA as part of the string and it kept giving me a parsing error even though technically the XML was correct. I had to write this formula to strip it out, and then it worked. In this case I knew it would always be there so I didn’t do any conditional checking. It seems silly that I had to do this, but couldn’t find any other way:

    substring-before(substring-after($Start/pfx2:metadata, “<![CDATA["), "]")

    Hopefully that helps someone

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s