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 -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -