How to Pass XML Message Embedded In another XML

Banner

02 Feb 2016

While developing Web Services it is necessary to send an XML message embedded in a SOAP envelope. XML messaging specification is based on the basic principle of providing a simple way to transport multiple XML documents within one logical XML construct without dictating any layered semantics of a messaging protocol that might be layered on top. The general philosophy is to provide the general structure upon which messaging protocols for specific business or technsological purposes can be layered allowing the identification of that messaging intent but not dictating the exact syntax and semantics of the subject message. In this way, manifests, metadata, and other messaging specific constructs can be tailored to specific vertical markets or technology applications.

For example:

If you are sending an XML message as one of the Property Sets for a workflow which will be later interpreted using Integration object. And you inserted an xml message inside an SOAP element hoping that Siebel would consider that as string of characters. But it considered that as having a special meaning. The partial SOAP envelope is below.

<cus:IncomingXML>

<OpportunityBase>

<Name>t40174</Name>

<Contact>

<FirstName>Robert</FirstName>

<LastName>DCosta</LastName>

</Contact>

<OpportunityBase>

</cus:IncomingXML>

Where the element IncomingXML contains one of the input propertysets in the workflow. When Siebel receives this message it would parse the entire XML and not ignore the special characters.

To avoid having parser to understand that there is an embedded xml message inside the xml element we enclose the message inside a CDATA (Character Data) block like in the below case. When the parser sees the CDATA, it understands that as an actual message and not to parse it.

<cus:IncomingXML>

<![CDATA[

<OpportunityBase>

<Name>t40174</Name>

<Contact>

<FirstName>Robert</FirstName>

<LastName>DCosta</LastName>

</Contact>

<OpportunityBase>

]]>

</cus:IncomingXML>

This way the actual message won’t be altered. Notice that the CDATA section starts with “<![CDATA[” and ends with “]]>“

Using CDATA we can also send functions, javascript, URLs etc. I believe that CDATA is used very often.

Also keep in mind that the message enclosed inside CDATA cannot contain “]]>” and nested CDATA is not allowed.

Let us know what you think. Post your comments.

Comments are closed.