XML-“无效的XML文档”。

时间:2019-03-04 04:16:08

标签: ruby-on-rails xml

我正在尝试更新Google联系人。 当我用下面的xml正文命中http请求时,出现错误 “无效的XML文档。”

下面是我的XML请求。

 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
    <entry>\n
      <category scheme=\"https://schemas.google.com/g/2005#kind\" term=\"https://schemas.google.com/contact/2008#contact\"/>\n
      <title>test Sun  1:00pm Kinjal S</title>\n
      <gd:name>\n
        <gd:fullName>test Sun  1:00pm Kinjal S</gd:fullName>\n</gd:name>
      <gd:phoneNumber label=\"Mobile\" primary=\"true\">+6598765432</gd:phoneNumber>
      <gd:phoneNumber label=\"Father\">+6598732465</gd:phoneNumber> 
      <gd:phoneNumber label=\"Friend\">+6589898989</gd:phoneNumber> 
      <gContact:groupMembershipInfo deleted=\"false\" href=\"https://www.google.com/m8/feeds/groups/paresh.tps@gmail.com/base/6\"/>\n
    </entry>"

有人可以帮助我解决此问题吗?

1 个答案:

答案 0 :(得分:2)

我认为未定义2个名称空间gdgContact。我刚刚添加了名称空间,这看起来不错。这是带有伪命名空间的修改后的XML(请相应地更正),

<?xml version="1.0" encoding="UTF-8"?>
<entry
    xmlns:gd = "http://www.w3.org/TR/html4/"
    xmlns:gContact = "http://www.w3.org/TR/html4/">
    <category scheme="https://schemas.google.com/g/2005#kind" term="https://schemas.google.com/contact/2008#contact"/>
    <title>test Sun  1:00pm Kinjal S</title>
    <gd:name>
        <gd:fullName>test Sun  1:00pm Kinjal S</gd:fullName>
    </gd:name>
    <gd:phoneNumber label="Mobile" primary="true">+6598765432</gd:phoneNumber>
    <gd:phoneNumber label="Father">+6598732465</gd:phoneNumber>
    <gd:phoneNumber label="Friend">+6589898989</gd:phoneNumber>
    <gContact:groupMembershipInfo deleted="false" href="https://www.google.com/m8/feeds/groups/paresh.tps@gmail.com/base/6"/>
</entry>