输出原始xml

时间:2014-03-11 14:52:04

标签: php xml

我正在编写一个脚本,用于将多个RSS源合并到一个使用php ...我的目标是让合并的源显示为一个RAW XML文件

这是我的合并代码:

$feeds = array(
    'http://feed1',
    'http://feed2',
    );

$entries = array();

foreach ($feeds as $feed) 
{
    $xml = simplexml_load_file($feed);
    $entries = array_merge($entries, $xml->xpath('/rss//item'));
    //var_dump ($xml);exit;
}

usort($entries, function ($x, $y)
 {
    return strtotime($x->pubDate) - strtotime($y->pubDate);
 });


print_r($entries);

为上面的代码做一个print_r给我这个输出:

Array ( [0] => SimpleXMLElement Object ( [title] => New Jersey Celebrates 'Bacon Week' [description] => Bacon lovers visiting Atlantic City. (Feb. 11) [guid] => 3028082 [pubDate] => Tue, 11 Feb 2014 06:28:53 GMT [enclosure] => SimpleXMLElement Object ( [@attributes] => Array ( [length] => 18656689 [type] => video/quicktime [url] => http://mediafilename/news-video/MMFWot0BJ0-3RNi7Anmvpw-853x480-1.mov ) ) ).....

我的愿望是显示一个带有所有各种xml标签的正确xml文件(原始xml)。

1 个答案:

答案 0 :(得分:0)

您必须将实例导出到xml并在之前发送正确的标头。试试这个:

header('Content-Type: text/xml');
print $entries->asXML();

更多信息: http://www.php.net/manual/it/simplexmlelement.asxml.php