Вопрос

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.

Это было полезно?

Решение 2

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

Другие советы

There are five "illegal" characters in XML that have to be encoded as entities:

< as &lt;
> as &gt;
' as &apos;
" as &quot;
& as &amp;

Which is what HttpUtility.HtmlEncode() effectively does.

There are others, such as the umlaut characters, that should be encoded when used in HTML, but for Unicode XML, only those five absolutely have to be taken care of.

I would actually use System.Net.WebUtility.HtmlEncode() as opposed to HttpUtility.HtmlEncode() because HttpUtility is not supported in partial-trust environments. In other words, in a sandboxed plugin as for CRM Online.

@GCATNIM correctly mentions the "illegal characters" which would be covered by both of these methods.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top