ブラウザが有効なxmlを期待しているヘッダーコンテンツタイプを設定することにより、適切なXMLを出力していないため、XML解析エラーが発生します。
これを試して:
<?php
header('Content-type: text/xml');
//Load your feed (input)
$feed = file_get_contents('http://rss.news.yahoo.com/rss/topstories');
$feed_xml = simplexml_load_string($feed);
//Create a new SimpleXMLElement object (for output)
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><news/>');
//Loop each item from $feed_xml->channel->item
foreach ($feed_xml->channel->item as $item) {
//Create a story node for each item
$node = $xml->addChild('story');
//Loop each items & add it to the node if its a title or description
foreach($item as $key=>$value){
if($key == 'title'){$node->addChild($key, $value);}
if($key == 'description'){$node->addChild($key, $value);}
}
}
//Use dom document to format the output nicly, not required
$dom = new DOMDocument('1.0');
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
echo $dom->saveXML();
/**Output
<?xml version="1.0" encoding="UTF-8"?>
<news>
<story>
<title>Ryan says Obama undercuts welfare reform law</title>
<description>Republican vice presidential candidate Paul Ryan says President Barack Obama wants to ease work requirements for welfare recipients even though that claim has been largely debunked by independent fact checkers.</description>
</story>
<story>
<title>Greenpeace activists storm Russian oil rig</title>
<description><p><a href="http://news.yahoo.com/greenpeace-activists-storm-russian-oil-rig-063813773.html"><img src="http://l3.yimg.com/bt/api/res/1.2/mSCkTQFkrkzOGPzb3sGLVw--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/ap_webfeeds/2c763e62d83a2717190f6a7067003ab4.jpg" width="130" height="86" alt="Greenpeace activists including Executive Director of Greenpeace International, Kumi Naidoo, board energy giant Gazprom's Arctic oil platform Prirazlomnaya off the North-eastern coast of Russia in the Pechora Sea on Friday, Aug. 24, 2012. Greenpeace activists have stormed a floating oil rig in Russia’s Pechora Sea to protest oil drilling in the Arctic, the environmental organization said on Friday. (AP Photo/ Denis Sinyakov, Greenpeace)" align="left" title="Greenpeace activists including Executive Director of Greenpeace International, Kumi Naidoo, board energy giant Gazprom's Arctic oil platform Prirazlomnaya off the North-eastern coast of Russia in the Pechora Sea on Friday, Aug. 24, 2012. Greenpeace activists have stormed a floating oil rig in Russia’s Pechora Sea to protest oil drilling in the Arctic, the environmental organization said on Friday. (AP Photo/ Denis Sinyakov, Greenpeace)" border="0" /></a>Greenpeace activists stormed a floating Russian oil rig early Friday in the open sea to protest oil drilling in the Arctic, the environmental organization said.</p><br clear="all"/></description>
</story>
...
...
</news>
*/
?>