douluogu8713 2014-08-11 04:20
浏览 29
已采纳

DOMDocument()xmlns提供“</>”而不是“<>”为谷歌产品创建无效文档。

I'm attempting to create a valid product feed for google shopping. All is well except this issue here.

DOMDocument() is creating this:

<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0"/>

Whereas the objective is this:

<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0">

Note the missing "/"

I thought < /> was perfectly valid code, but google is rejecting it with this error:

XML formatting error - Error

Our system encountered an error when processing your data feed. Learn more. Examples: Line Nr. 3 Column Nr. 1

That of course relates to the above tag I mentioned.

The doc starts off this way...

<?xml version="1.0"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0"/>
<channel>
...

I'm not aware there are any issues, yet google says its in error.

<?php
$xml = new DOMDocument(); 


$rss = $xml->createElement('rss');
$version = $xml->createAttribute('version');
$rss->appendChild($version);
$value = $xml->createTextNode('2.0');
$version->appendChild($value);


$xmlns_g = $xml->createAttribute('xmlns:g');
$rss->appendChild($xmlns_g);

$value = $xml->createTextNode('http://base.google.com/ns/1.0');
$xmlns_g->appendChild($value);

$xmlns_c = $xml->createAttribute('xmlns:c');
$rss->appendChild($xmlns_c);

$value = $xml->createTextNode('http://base.google.com/cns/1.0');
$xmlns_c->appendChild($value);

$xml->appendChild($rss);
?>
  • 写回答

1条回答 默认 最新

  • donglin4636 2014-08-11 04:31
    关注

    Somewhere further in the code you have something that reads like this:

    $channel = $xml->createElement('channel');
     ...
    $xml->appendChild($channel);
    

    This is incorrect.

    This will add children to the document itself. You must add children to existing nodes, among them the root rss node.

    $channel = $xml->createElement('channel');
     ...
    $rss->appendChild($channel);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C