我在查詢Web服務(雅虎天氣)時遇到問題。感謝這個很酷的論壇,我發現了以下hint。不過,我無法找回我的價值。PHP XML 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提取CDATA部分總是空的。
描述是這樣的
Current Conditions:
Mostly Cloudy, 50 F
Forecast:
Fri - Partly Cloudy. High: 62 Low: 49
Sat - Partly Cloudy. High: 65 Low: 49
Full Forecast at Yahoo! Weather
(provided by The Weather Channel)
]]>