【发布时间】:2011-03-02 10:05:29
【问题描述】:
我正在尝试使用 SimpleXML 生成一个 RSS Google Merchant。
谷歌给出的示例是:
<?xml version="1.0"?>
<rss version="2.0"
xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>The name of your data feed</title>
<link>http://www.example.com</link>
<description>A description of your content</description>
<item>
<title>Red wool sweater</title>
<link> http://www.example.com/item1-info-page.html</link>
<description>Comfortable and soft, this sweater will keep you warm on those cold winter nights.</description>
<g:image_link>http://www.example.com/image1.jpg</g:image_link> <g:price>25</g:price> <g:condition>new</g:condition> <g:id>1a</g:id>
</item>
</channel>
</rss>
我的代码有这样的东西:
$product->addChild("g:condition", 'new');
生成:
<condition>new</condition>
我在网上看到我应该改用:
$product->addChild("g:condition", 'new', 'http://base.google.com/ns/1.0');
现在生成:
<g:condition xmlns:g="http://base.google.com/ns/1.0">new</g:condition>
这对我来说似乎很违反直觉,因为现在“xmlns”声明几乎出现在我的 RSS 提要的每一行,而不是根元素中只有一次。
我错过了什么吗?
【问题讨论】: