<?php 
//Esta funcion nos ayuda a sacar el atributo "data" del "tag" de un nodo dado
function getTagDataFromNode($tag,$node){
    
$child $node->get_elements_by_tagname($tag);
    
$data $child[0]->get_attribute_node('data');
    return 
$data->value();
}

//Abro la prediccion para madrid
$xml domxml_open_file('http://www.google.com/ig/api?hl=es&weather=Madrid');

$problem $xml->get_elements_by_tagname('problem_cause');
if(
$problem) {
    
$problem_cause $problem[0]->get_attribute_node('data');
    die(
$problem_cause);
} else {
    
//Extraigo la informacion de la prediccion
    
$infoTag $xml->get_elements_by_tagname('forecast_information');
    
$city getTagDataFromNode('city',$infoTag[0]); //La ciudad
    
$date getTagDataFromNode('forecast_date',$infoTag[0]); //La fecha de la prediccion

    
echo "<h1>Prediccion en $city ($date)</h1>";

    
//Prediccion para los proximos dias
    
$items $xml->get_elements_by_tagname('forecast_conditions');

    foreach(
$items as $item){
        echo 
"<p><strong>".getTagDataFromNode('day_of_week',$item)."</strong> <br>";
        echo 
"<img src=\"http://google.com".getTagDataFromNode('icon',$item)."\"><br>".getTagDataFromNode('condition',$item).".<br>";
        echo 
"Temperaturas entre ".getTagDataFromNode('low',$item)." &deg;C y ".getTagDataFromNode('high',$item)." &deg;C</p>";
    }
}
?>