Get xml attribute in PHP -


i want know temperature city using yahoo wheater (xml), xpath , php. code use doesn't work. can element (description) not attribute (temperature) want.

$xml = new domdocument(); $xml->load("http://weather.yahooapis.com/forecastrss?w=12818432&u=c");  $xpath = new domxpath($xml); $result = $xpath->query("//channel");  foreach ($result $value) {     //$weather = $value->getelementsbytagname("description");     $weather = $value->getelementsbytagname("yweather:wind");     $temp = $weather->getattribute("chill");      print $temp->item(0)->textcontent; } 

you should use getelementsbytagnamens() elements within namespace.

$ns_yweather = "http://xml.weather.yahoo.com/ns/rss/1.0"; $weer = $value->getelementsbytagnamens($ns_yweather, "wind")->item(0); print $weer->getattribute("chill"); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -