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>&lt;![CDATA[response content goes here]]&gt;</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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top