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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助