2012-07-05 44 views
3

我使用fetch xml來從ms crm 2011實體中重新獲取值。 它拋出INVALID XML錯誤,XML示例在下面給出:Crm 2011抓取XMl - 無效的XML問題,如何解決?

<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> 

通過invistigating問題,我發現的原因是1和2之間的&符號:

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

1-有人可以幫我解決這個問題嗎?

2 - 什麼是其他非法字符,所以我可以處理?

問候。

回答

5

有在XML五「非法」字符必須被編碼爲實體:

< as & lt;
> as & gt;
' as &'
" as &「
&爲&安培;

這是什麼HttpUtility.HtmlEncode()有效呢。

還有其他的,如元音字符,在HTML中使用時,應進行編碼的,但對Unicode的XML,只有五絕,必須照顧。

2

我實際上使用System.Net.WebUtility.HtmlEncode()而不是HttpUtility.HtmlEncode(),因爲部分信任環境中不支持HttpUtility。換句話說,在CRM Online中的沙盒插件中。

@GCATNIM正確地提到了「非法字符」,這將通過這兩種方法所覆蓋。