&安培;符号导致XML代码中的错误

时间:2014-10-20 17:39:49

标签: xml filter dynamics-crm-2013

我有以下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);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

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

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

或者,你可以放置&#34; text&#34;字符串可能包含CDATA部分中的特殊字符,因此XML解析器不会尝试解析它们。例如:

<SomeElement><![CDATA[This & will be ignored]]></SomeElement>
相关问题