Php 向生成的XML标记添加版本

Php 向生成的XML标记添加版本,php,xml,rss,Php,Xml,Rss,我正在尝试制作一个RSS提要XML,我发现了一个网站,在那里他们给出了一个XML应该是什么样子的示例: <?xml version="1.0"?> <rss version="2.0"> <channel> <title>The Channel Title Goes Here</title> <description>The explanation of how the items are related goes her

我正在尝试制作一个RSS提要XML,我发现了一个网站,在那里他们给出了一个XML应该是什么样子的示例:

<?xml version="1.0"?>
<rss version="2.0">
<channel>

<title>The Channel Title Goes Here</title>
<description>The explanation of how the items are related goes here</description>
<link>http://www.directoryoflinksgohere</link>

<item>
<title>The Title Goes Here</title>
<description>The description goes here</description>
<link>http://www.linkgoeshere.com</link>
</item>

<item>
<title>Another Title Goes Here</title>
<description>Another description goes here</description>
<link>http://www.anotherlinkgoeshere.com</link>
</item>

</channel>
</rss>

频道标题在这里
这里将解释这些项目之间的关系
http://www.directoryoflinksgohere
标题在这里
这里有描述
http://www.linkgoeshere.com
另一个标题在这里
这里还有另一种描述
http://www.anotherlinkgoeshere.com
但是,当我检查当前的XML时,我注意到XML和rss标记中没有显示版本

<xml>
<rss>
<channel>
<title>#####</title>
<description>
#####
</description>
<path>#####</path>

#####
#####
#####
如何将版本添加到XML和RSS的开始标记中

PHP

$newspages = $this->newspages;

$xml = new SimpleXMLElement('<xml/>');

$rss = $xml->addChild('rss');

$channel = $rss->addChild('channel');

$channel->addChild('title', txt('rss.channelname'));
$channel->addChild('description', txt('rss.channeldescription'));
$channel->addChild('path', 'http://'.$_SERVER['HTTP_HOST']);

foreach ($newspages as $newspage) {
    if ($newspage['id'] !== 'news-archive') {
        $item = $channel->addChild('item');
        $item->addChild('title', $newspage['title']);
        $item->addChild('description', $newspage['description']);
        $item->addChild('path', url('###/pageid', array('language'=>$this->language, 'id'=>$newspage['id'])));
    }
}

Header('Content-type: text/xml');

print($xml->asXML());
$newspages=$this->newspages;
$xml=新的SimpleXMLElement(“”);
$rss=$xml->addChild('rss');
$channel=$rss->addChild('channel');
$channel->addChild('title',txt('rss.channelname');
$channel->addChild('description',txt('rss.channeldescription');
$channel->addChild('path','http://'。$\u SERVER['http\u HOST']);
foreach($newspages作为$newspage){
如果($newspage['id']!=='news archive'){
$item=$channel->addChild('item');
$item->addChild('title',$newspage['title']);
$item->addChild('description',$newspage['description']);
$item->addChild('path',url('###/pageid',array('language'=>$this->language,'id'=>$newspage['id']));
}
}
标题('Content-type:text/xml');
打印($xml->asXML());

使用addAttribute方法

<?php

$xml = new SimpleXMLElement('<xml/>');
$xml->addAttribute('version', '1.0');

$rss = $xml->addChild('rss');
$rss->addAttribute('version', '2.0');
addAttribute('version','1.0');
$rss=$xml->addChild('rss');
$rss->addAttribute('version','2.0');

xml不是元素,而是标题。