A CData section can be used to embed an XML document within another XML document.
What is a CData section?
An XML element can contain text content:<element>text content</element>
However,
some characters cannot appear in that content. In particular, '<'
and '&' both have special meaning to an XML parser. If they are
included in the text content of an element, they change the meaning
of the XML document. <element><text><content></element>
<element><text><content></element>
<element><![CDATA[<text><content>]]></element>
What can you use a CData section for?
In a CData section, you can include XML markup in the value of an element. However, non-valid XML characters cannot be included. Binary data also cannot be included in a CData section.<outer>
<embedXML>
<![CDATA[<innerMsg></innerMsg>]]>
</embedXML>
</outer>
<outer>
<embedXML>
<![CDATA[<badXML></wrongClosingTag>]]>
</embedXML>
</outer>
The following items are not valid within a
CData section: How do you add a CData section to an output XML message?
Consider the following input message :
<TestCase>
<Folder>
<Field1>Value1</Field1>
<Field2>Value2</Field2>
<Field3>Value3</Field3>
</Folder>
</TestCase>
The following ESQL shows how to serialize
a whole message: DECLARE wholeMsgBlob BLOB
ASBITSTREAM(InputRoot.XMLNSC,
InputRoot.Properties.Encoding,
InputRoot.Properties.CodedCharSetId );
DECLARE wholeMsgChar CHAR
CAST(wholeMsgBlob AS CHAR CCSID InputRoot.Properties.CodedCharSetId);
SET OutputRoot.XMLNSC.Output.(XMLNSC.CDataField)Field1 = wholeMsgChar;
This example serializes the InputRoot.XMLNSC.TestCase.Folder portion of the message tree.
If the output message tree were examined before an MQOutput node, this would show :
(0x01000010):XML = (
(0x01000000):Output = (
(0x01000000):Field1 = (
(0x02000001): = '<TestCase><Folder><Field1>Value1</Field1><Field2>Value2</Field2>
<Field3>Value3</Field3></Folder><Folder2><Field1>Value1</Field1>
<Field2>Value2</Field2><Field3>Value3</Field3><Folder2></TestCase>'
)
)
)
As can be seen, each CData section contains a single scalar value that is the character representation of the portion of the XML message that is required.
This tree produces the following XML output message :
<Output>
<Field1><![CDATA[<TestCase><Folder><Field1>Value 1</Field1>
<Field2>Value 2</Field2>
<Field3>Value 3</Field3></Folder>
<Folder2><Field1>Value 1</Field1>
<Field2>Value 2</Field2>
<Field3>Value 3</Field3></Folder2>
</TestCase>]]</Field1>
</Output>