Adding CDATA section to XML element

13 Aug, 2018 | 3 minutes read

This post explains the process of adding a CDATA section to an XML element using the RenderXML activity in BW6. The Tibco BW documentation (RenderXML section) contains a very basic explanation for achieving this goal, however, I would like to explain the steps required regarding these two cases:

  • having schema with elements defined not as global;
  • having schema with no default namespace;

In short, the solution lies in altering the .bwp process in some text editor and wrapping the elements in CDATA. But let us go through the long path:

Case 1: Adding CDATA section to XML elements not defined as global

Specific for this case is that when the elements in the schema are not defined as global (under root element), they are not displayed to be selected when clicking the plus button under the Advanced tab of the RenderXML activity. Here is an explanation of the steps needed to achieve that.


Snippet of the input message:


<?xml version="1.0" encoding="UTF-8"?>
<cd:CATALOG xmlns:cd="http://www.w3.org/2001/XMLSchema/cdcatalog">
	<cd:CD>
		<cd:TITLE>Empire Burlesque</cd:TITLE>
		<cd:ARTIST>Bob Dylan</cd:ARTIST>
		<cd:COUNTRY>USA</cd:COUNTRY>
		<cd:COMPANY>Columbia</cd:COMPANY>
		<cd:PRICE>10.90</cd:PRICE>
		<cd:YEAR>1985</cd:YEAR>
	</cd:CD>
	<cd:CD>
		<cd:TITLE>Hide your heart</cd:TITLE>
		<cd:ARTIST>Bonnie Tyler</cd:ARTIST>
		<cd:COUNTRY>UK</cd:COUNTRY>
		<cd:COMPANY>CBS Records</cd:COMPANY>
		<cd:PRICE>9.90</cd:PRICE>
		<cd:YEAR>1988</cd:YEAR>
	</cd:CD>
	 …
</cd:CATALOG>

Step1: Click the + button under the Advanced tab of the RenderXML activity. Only the root element – CATALOG is displayed. Select the root element.

Selecting root element

The CATALOG element will be displayed under the Advanced tab.

Searching for the Catalog element

Step2: Open the. bwp process in notepad editor. Search “cdata” and find the CATALOG element.

Open the. bwp process in notepad editor

Step3: Replace CATALOG with the element that is required to have CDATA section, in the example I will use TITLE and COMPANY. Save the changes and refresh the module in BW6 studio in order the changes to take effect.

Replace CATALOG with the element that is required to have CDATA section, here is used TITLE and COMPANY

Opening Advanced Tab under RenderXML activity should contain the changes made.

Opening Advanced Tab under RenderXML activity should contain the changes made.

Validation, the output xml contains TITLE and COMPANY elements with values wrapped in CDATA section.

Validation, the output xml contains TITLE and COMPANY elements with values wrapped in CDATA section.

Case 2: Adding CDATA to XML elements not defined as global in schema without default namespace

CATALOG element will be displayed under Advanced tab. Notice, unlike the first scenario the namespace is defined as {null}.

This is similar like the previous scenario, specific is that one additional change needs to be made for the final result to be met.

Step1: Click the + button under the Advanced tab of the RenderXML activity. Only the root element – CATALOG is displayed. Select the root element – CATALOG.
CATALOG element will be displayed under Advanced tab. You can notice that unlike the first scenario the namespace is defined as {null}.

Repeat Steps 2,3 from previous scenario.

Replace CATALOG element with elements that are required to have CDATA section. In this example TITLE and ARTIST.

Replace CATALOG element with elements that are required to have CDATA section. In this example TITLE and ARTIST.

Replace CATALOG element with elements that are required to have CDATA section. In this example TITLE and ARTIST.

Refresh module in designer.

CATALOG element will be displayed under Advanced tab.

Configured like this, the code will not produce the desired output. This is caused by the {null} part.
Even though {null} points that no namespace is defined, the XSLT processor actually is looking for element TITLE with namespace null.

Step4: To fix this, you should manually remove the null part.

Manually removing the null part

Refresh module in designer.

Refresh module in designer.

Validation: the output xml contains TITLE and ARTIST elements with values wrapped in CDATA section.

the output xml contains TITLE and ARTIST elements with values wrapped in CDATA section.