PHP:使用curl获取文件的XML解析 - 无法解析为XML对象?

Hey guys so I have the following script which does seem to work as expected because the curl returns a blurb of text instead:

<?php

function download_page($path){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $path);
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $retValue = curl_exec($ch);          
    curl_close($ch);
    return $retValue;
}

$xml_str = download_page('http://api.npr.org/list?id=3002');
echo $xml_str; //SPITS OUTS A BLURB OF TEXT
$xml = new SimpleXMLElement(file_get_contents("test.xml"));
$items = $xml->xpath('*/item');
print_r($items); //RETURNS Array()
foreach($items as $item) {
    echo "one time";
    echo $item['title'], ': ', $item['description'], "
";
}
?>

I have no idea how to download the XML page into a normal XML format rather than this blurb of text.

Try using sending a request to get text/xml from the server.

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/xml"));

or using application/xml.