Error with ampersand in XML in Zoho API

被刻印的时光 ゝ 提交于 2019-12-04 05:01:39

问题


I'm using the Zoho API to insert leads into the CRM.

Everything is working fine except when one of the fields contains an ampersand, in which case the response from Zoho is this:

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/insertRecords">
  <error>
    <code>4835</code>
    <message>Unable to parse XML data</message>
  </error>
</response>

I've tried the following payloads without any success:

1/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company">Marks & Spencer</FL>
    </row>
</Leads>

2/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company">Marks &amp; Spencer</FL>
    </row>
</Leads>

3/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company">Marks &#038; Spencer</FL>
    </row>
</Leads>

4/

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company"><![CDATA[Marks &amp; Spencer]]></FL>
    </row>
</Leads>

I've even tested by replacing the ampersand by %26 as advised on this Zoho forum thread but with no luck.

What is the correct format to encode ampersands for Zoho queries?


回答1:


Finally found a solution: strings containing a special characters must be contained in CDATA sections AND those special characters need to be percent encoded.

So for the example above, this gives:

<Leads>
    <row no="1">
        <FL val="Lead Owner">me@example.com</FL>
        <FL val="Company"><![CDATA[Marks %26 Spencer]]></FL>
    </row>
</Leads>

Note that the value Marks%20%26%20Spencer is also OK for the API.



来源:https://stackoverflow.com/questions/35742554/error-with-ampersand-in-xml-in-zoho-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!