我有以下 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);
}
}
}
有些字符在 XML 中具有特殊含义,与号 (&) 就是其中之一。因此,这些字符应该用它们各自的实体引用来替换(即使用字符串替换)。根据 XML 规范,有 5预定义实体 http://www.w3.org/TR/REC-xml/#sec-predefined-ent in XML:
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
或者,您可以将可能包含特殊字符的“文本”字符串放置在 CDATA 部分中,这样 XML 解析器就不会尝试解析它们。例子:
<SomeElement><![CDATA[This & will be ignored]]></SomeElement>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)