我正在使用SimpleXML为Google产品创建RSS Feed,我想创建一个名称空间的子代,但是当我这样做时
$item->addChild('g:id', 'myid');
它添加了
<id>myid</id>
而不是
<g:id></g:id>
此外我已在顶部添加
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
如何添加命名空间的孩子?
答案 0 :(得分:14)
命名空间是addChild()
$item->addChild('id', 'myid', 'http://base.google.com/ns/1.0');
See the documentation了解更多信息。
答案 1 :(得分:3)
在不知道这是否是这样做的官方方式的情况下,我发现了一些能够完成这项工作的东西:
$item->addChild('g:g:id', 'myid');
在此代码http://www.sanwebe.com/2013/08/creating-rss-feed-using-php-simplexml
上找到此信息