【问题标题】:& Symbol causing error in XML Code& 导致 XML 代码错误的符号
【发布时间】:2014-10-20 17:39:49
【问题描述】:

我有以下 XML 代码在我的 Crm Dynamics 表单中过滤我的查找字段。 在输入到帐户字段中的数据之后使用过滤器。但是,帐户字段可以包含 & 符号,如果包含,则会出现错误,指出 XML 格式不正确。

有没有人可以解决这个问题?

function accountcontact()
{
    Xrm.Page.getControl("new_contactlookup").addPreSearch(function () { addcontactlookup(); });

    function addcontactlookup()
    {
        var accountID = Xrm.Page.getAttribute("new_companylookup");
        var AccountIDObj= accountID.getValue();

        if (AccountIDObj != null)
        {
            var fetchFilter1 = "<filter type='and'><condition attribute='parentcustomerid' uitype='" + AccountIDObj[0].entityType + "' operator='eq' value='" + AccountIDObj[0].id + "' uiname='" + AccountIDObj[0].name + "' /></filter>";
            Xrm.Page.getControl("new_contactlookup").addCustomFilter(fetchFilter1);
        }
    }
}

【问题讨论】:

  • 必须转义为&amp;amp; 使用实用函数(我假设是JavaScript):how to escape xml entities in javascript?
  • 为什么要使用 javascript 添加过滤器,而不是通过使用 OOB 工具修改表单来按帐户过滤联系人?

标签: xml filter dynamics-crm-2013


【解决方案1】:

某些字符在 XML 中具有特殊含义,和号 (&) 就是其中之一。因此,应该用它们各自的实体引用替换这些字符(即使用字符串替换)。根据 XML 规范,XML 中有 5 个predefined entities

&lt;    <   less than
&gt;    >   greater than
&amp;   &   ampersand 
&apos;  '   apostrophe
&quot;  "   quotation mark

或者,您可以将可能包含特殊字符的“文本”字符串放在 CDATA 部分中,这样 XML 解析器就不会尝试解析它们。示例:

<SomeElement><![CDATA[This & will be ignored]]></SomeElement>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 2016-02-09
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多