Je suis d'accord que l'utilisation de l'analyseur XML simple de php est la voie à suivre avec celui-ci. Vous pouvez vous faciliter la vie ici en utilisant la méthode xpath
pour extraire des données du fichier xml.
Il y a un tutoriel XPath ici: http://www.w3schools.com/xpath/
et documentation php pour ici: http://www.php.net/manual/en/simplexmlelement.xpath.php
Essayez ceci
<?php
/*
Get the file with CURL
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'ftp://ftp2.bom.gov.au/anon/gen/fwo/IDV10753.xml');
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,true);
$xml_data = curl_exec($curl_handle);
curl_close($curl_handle);
*/
/*
Open the file locally
*/
$xml_data = file_get_contents("weather.xml");
$xml = simplexml_load_string($xml_data);
$result = $xml->xpath("//area[@description='Swan Hill']/forecast-period");
date_default_timezone_set('America/New_York');
foreach ($result as $day) {
//print_r($day);
$day_of_the_week = date("l", strtotime($day["start-time-local"])); //start-time-local is an attribute of a result, so use the [] syntax
$forecast = $day->text; //text is a child node, so use the -> syntax
printf("%s: %s\n", $day_of_the_week, $forecast);
}
?>
EDIT exemple Plus illustrative
Je ne peux pas comprendre comment sélectionner l'élément avec le type de 'air_temperature_maximum' J'ai essayé d'utiliser ceci mais cela n'a pas fonctionné $ max = $ jour-> xpath ("element [@ type = 'air_temperature_maximum']"); celui-ci fonctionne: $ min = $ jour-> élément [1]; mais il ne me donne pas le contrôle approprié sur ce qu'il faut afficher en cas d'un champ est manquant. – Honshi