【问题标题】:Crm 2011 Fetch XMl - Invalid XML issue, how to fix?Crm 2011 Fetch XMl - 无效的 XML 问题,如何解决?
【发布时间】:2012-07-05 16:32:00
【问题描述】:

我正在使用 fetch xml 从 ms crm 2011 实体中检索值。 它会抛出 INVALID 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>

通过调查问题,我发现原因是 1 和 2 之间的 & 符号:

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

1- 有人可以帮我解决这个问题吗?

2- 还有哪些非法字符可以处理?

问候。

【问题讨论】:

    标签: xml dynamics-crm-2011 fetchxml


    【解决方案1】:

    XML 中有五个“非法”字符必须编码为实体:

    > 作为 >
    ' 作为 '
    “作为”
    & 作为 &

    HttpUtility.HtmlEncode() 的实际作用是什么。

    还有一些其他字符,例如元音变音字符,在 HTML 中使用时应该进行编码,但对于 Unicode XML,只有这五个绝对需要处理。

    【讨论】:

      【解决方案2】:

      HttpUtility.HtmlEncode() 通过处理非法字符 (&'") 为我工作。

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

      请参阅下面的文章了解更多详情。

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

      【讨论】:

        【解决方案3】:

        我实际上会使用System.Net.WebUtility.HtmlEncode() 而不是HttpUtility.HtmlEncode(),因为部分信任环境不支持HttpUtility。换句话说,在 CRM Online 的沙盒插件中。

        @GCATNIM 正确地提到了这两种方法都会覆盖的“非法字符”。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-03-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-03-02
          • 2013-03-24
          • 1970-01-01
          相关资源
          最近更新 更多