【发布时间】:2013-10-02 12:36:18
【问题描述】:
我在查询网络服务(雅虎天气)时遇到问题。感谢这个很酷的论坛,我找到了以下hint。然而,我无法找回我的价值。
我正在使用提取 CDATA 部分
$conditionIcon = $weatherXmlObject->xpath("//item/description");
$dom = new DOMDocument();
$dom->loadHTML($conditionIcon); // or you can use loadXML
$xml = simplexml_import_dom($dom);
$imgSrc = (string)$xml->body->img['src'];
echo $imgSrc;
$imgSrc 始终为空。
描述如下
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 50 F<BR />
<BR /><b>Forecast:</b><BR />
Fri - Partly Cloudy. High: 62 Low: 49<br />
Sat - Partly Cloudy. High: 65 Low: 49<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
【问题讨论】:
标签: php xml cdata yahoo-api yahoo-weather-api