错误/警告解析RSS XML :(

问题描述:

我这样做错误/警告解析RSS XML :(

<blink> 
$xml = file_get_contents(http://weather.yahooapis.com/forecastrss?w=12797541); 
$yahoo_response = new SimpleXMLElement($xml , 0, true); 
</blink> 

而且我得到了一个XML解析这样的警告:

PHP Warning: SimpleXMLElement::__construct() 
[<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: 
I/O warning : failed to load external entity &quot;&lt;?xml version=&quot;1.0&quot; 

.....

一个重要的部分消息是这样的:

I/O warning : failed to load external entity 

And I co üld不解析任何东西:

echo (string) $yahoo_response->rss->channel->item->title; 

有没有人知道如何解决这个问题或解决它?

谢谢, 亚历克斯

SimpleXMLElement()第三个参数指定是否$data是URL。你应该这样做要么

$xml = file_get_contents('http://weather.yahooapis.com/forecastrss?w=12797541'); 
$yahoo_response = new SimpleXMLElement($xml , 0, false); // false, not true 

$xml = 'http://weather.yahooapis.com/forecastrss?w=12797541'; // url, not contents 
$yahoo_response = new SimpleXMLElement($xml , 0, true); 
+0

那固定的错误和警告。谢谢。但是我怎么仍然没有从echo $ yahoo_response-> rss-> channel-> item-> title返回任何东西; – Genadinik 2011-02-24 08:04:01

+0

我不确定(有一段时间没有用过SimpleXML),但我相信'$ yahoo_response'指向''元素。尝试打印'$ yahoo_response-> channel-> item-> title'。你也应该看看手册(http://lv.php.net/SimpleXMLElement)。 – binaryLV 2011-02-24 08:12:34