1
我想通過使用Yahoo Wheater(xml),xpath和php來了解城市的溫度。 這是我使用的代碼,但它不起作用。我可以得到一個元素(描述),但不是我想要的屬性(溫度)。在PHP中獲取xml屬性
$xml = new DOMDocument();
$xml->load("http://weather.yahooapis.com/forecastrss?w=12818432&u=c");
$xpath = new DOMXpath($xml);
$result = $xpath->query("//channel");
foreach ($result as $value) {
//$weather = $value->getElementsByTagName("description");
$weather = $value->getElementsByTagName("yweather:wind");
$temp = $weather->getAttribute("chill");
print $temp->item(0)->textContent;
}