加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – BizTalk – CDATA的消息分配形状

发布时间:2020-12-16 23:50:28 所属栏目:百科 来源:网络整理
导读:我在Orchestration的Message Assignment形状中设置元素的值.我正在使用XPATH函数来做到这一点. 该文本需要包含在CDATA部分中.这就是我尝试这样做的方式: xpath(messageOut,"//Envelope/Body/MsgFFmt") = @"![CDATA[" + _response + @"]]"; 但是,BizTalk将其
我在Orchestration的Message Assignment形状中设置元素的值.我正在使用XPATH函数来做到这一点.

该文本需要包含在CDATA部分中.这就是我尝试这样做的方式:

xpath(messageOut,"//Envelope/Body/MsgFFmt") = @"<![CDATA[" + _response + @"]]>";

但是,BizTalk将其转义并且元素内的文本最终看起来像这样:

<MsgFFmt>&lt;![CDATA[response content goes here]]&gt;</MsgFFmt>

我似乎无法在网上找到关于指示BizTalk我需要围绕我的_response字符串的CDATA部分的任何内容.有人可以帮忙吗?

谢谢

我会回答我自己的问题,以便在有人看的时候分享.这是基于这篇文章: http://soa-thoughts.blogspot.co.nz/2007/07/cdata-mapping-experience-inside-biztalk.html

我最终创建了一个Helper类:

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;
    }
}

这是DLL在GAC之后从形状中调用它的方法:

MessageOut = MessageHelper.SetCDATASection(MessageOut,"/Envelope/Body/MsgFFmt",_string);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读