问题
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);
}
}
}
回答1:
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:
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
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>
来源:https://stackoverflow.com/questions/26471640/symbol-causing-error-in-xml-code