I am setting the value of an element inside a Message Assignment shape of an Orchestration. I am using XPATH function to do it.
The text needs to be contained inside a CDATA section. This is how I tried to do it:
xpath(messageOut, "//Envelope/Body/MsgFFmt") = @"<![CDATA[" + _response + @"]]>";
However, BizTalk escapes it and the text inside the element ends up looking like this:
<MsgFFmt><![CDATA[response content goes here]]></MsgFFmt>
I can't seem to find anything on the web in regards to instructing BizTalk that I need a CDATA section around my _response string. Anybody can help?
Thanks
I'll answer my own question to share it in case someone is looking. This was based on this post: http://soa-thoughts.blogspot.co.nz/2007/07/cdata-mapping-experience-inside-biztalk.html
I ended up creating a Helper class:
public class MessageHelper
{
/// <summary>
/// Sets a CDATA section in a XLANG message.
/// </summary>
/// <param name="message">The xlang message.</param>
/// <param name="xPath">The xpath for the element which will contain the CDATA section.</param>
/// <param name="value">The contents of the CDATA section.</param>
/// <returns>The resulting xml document containing the CDATA section</returns>
public static XmlDocument SetCDATASection(XLANGMessage message, string xPath, string value)
{
if (message == null)
throw new ArgumentNullException("message");
if (message[0] == null)
throw new ArgumentNullException("message[0]");
var xmlDoc = (XmlDocument)message[0].RetrieveAs(typeof(XmlDocument));
var cdataSection = xmlDoc.CreateCDataSection(value);
var node = xmlDoc.SelectSingleNode(xPath);
if(node !=null)
{
node.InnerText = String.Empty;
node.AppendChild(cdataSection);
}
return xmlDoc;
}
}
This is how you call it from the shape after the DLL was GAC:
MessageOut = MessageHelper.SetCDATASection(MessageOut, "/Envelope/Body/MsgFFmt", _string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With