Search code examples
xmldynamics-crm-2011fetchxml

Crm 2011 Fetch XMl - Invalid XML issue, how to fix?


I am using fetch xml to retieve values from ms crm 2011 entities. it throws INVALID XML error, the sample xml is given below:

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
    <entity name='xyz_registrationanswer'>
         <attribute name='xyz_registrationid' />
         <attribute name='xyz_name' />
         <filter type='and'> 
            <condition attribute='xyz_name' operator='in' >  
                <value>Do you want to subscribe to 1 & 2?</value>         
            </condition> 
        </filter> <order attribute='xyz_name' descending='false' />
    </entity>
</fetch>

By invistigating the issue i found the cause which is the & sign between 1 and 2:

<value>Do you want to subscribe to 1 & 2?</value> 

1- Can someone help me how to fix this issue?

2- What are other illegal characters so i can handle them?

Regards.


Solution

  • HttpUtility.HtmlEncode() worked for me, by handling the illegal characters(<>&'").

    <value>HttpUtility.HtmlEncode("Do you want to subscribe to 1 & 2?")</value>  
    

    See below article for more detail.

    How to locate and replace special characters in an XML file with Visual C# .NET