&引起XML代码错误的符号 [英] & Symbol causing error in XML Code

查看:98
本文介绍了&引起XML代码错误的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following XML code that is filtering my Lookup Field in my Crm Dynamics form. The filter is used following the data that is entered into the Account Field. However, the account field can contain the & symbol, and when it does, an error occurs stating that the XML is not well formed.

有人对这个问题有解决方案吗?

Does anyone have any solutions to the problem?

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


推荐答案

某些字符在XML中具有特殊含义,而&符(&)是其中之一。因此,应将这些字符替换为其相应的实体引用(即使用字符串替换)。根据XML规范,XML中有5个预定义实体

Some characters have special meaning in XML and ampersand (&) is one of them. Consequently, these characters should be substituted (ie use string replacement) with their respective entity references. Per the XML specification, there are 5 predefined entities in XML:

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

或者,您可以在CDATA部分中放置可能包含特殊字符的文本字符串因此XML解析器将不会尝试解析它们。例如:

Alternatively, you can place "text" strings that might contain special characters within a CDATA section so XML parsers will not attempt to parse them. Example:

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

这篇关于&amp;引起XML代码错误的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆