J'ai un piti problème pour extraire une ligne d'un fichier XML.
J'ai regardé du côté de DOMdocument, mais c'est carrément complexe !!! Du coup, j'ai regardé aussi du côté de SimpleXML qui me parait plus simple
Bref, j'arrive presque à faire ce que je veux, c'est à dire que je parviens à extraire le nom, la latitude et la longitude, mais je galère toujours sur le log !
Voici un extrait du fichier XML sur lequel je travaille (la structure se répète x fois sur le fichier, mais je n'en ai mis qu'une partie)
Code : Tout sélectionner
<wpt lat="49.3971" lon="4.695867">
<time>2013-06-02T07:00:00Z</time>
<name>GC4DD74</name>
<desc>Parc François Mitterrand by cachcaillou, Multi-cache (2/1.5)</desc>
<url>http://www.geocaching.com/seek/cache_details.aspx?guid=04118df7-1b3f-48e7-afdb-cf8f3d9290ba</url>
<urlname>Parc François Mitterrand</urlname>
<sym>Geocache Found</sym>
<type>Geocache|Multi-cache</type>
<groundspeak:cache id="3682961" available="True" archived="False" xmlns:groundspeak="http://www.groundspeak.com/cache/1/0">
<groundspeak:name>Parc François Mitterrand</groundspeak:name>
<groundspeak:placed_by>cachcaillou</groundspeak:placed_by>
<groundspeak:owner id="6968858">cachcaillou</groundspeak:owner>
<groundspeak:type>Multi-cache</groundspeak:type>
<groundspeak:container>Micro</groundspeak:container>
<groundspeak:difficulty>2</groundspeak:difficulty>
<groundspeak:terrain>1.5</groundspeak:terrain>
<groundspeak:country>France</groundspeak:country>
<groundspeak:state>Champagne-Ardenne</groundspeak:state>
<groundspeak:short_description html="True">Balade apaisante dans un parc de la ville. La cache finale se trouve aux coordonnées suivantes :<br />
<b>N 49° 23.BA6</b><br />
<b>E 004° 41.BB3</b>
</groundspeak:short_description>
<groundspeak:long_description html="True">Le Parc François Mitterrand, du nom d'un Président de la République, a été inauguré le 20 Octobre 1999 par son épouse Danielle Mitterrand.<br />
Vous y trouverez un écureuil géant surveillant l'entrée de sa banque voisine, des lycéens roucoulant dans les allées, ou parfois des moldus venus s'abreuver.<br />
La faune vouzinoise s'y promène dans un calme à peine troublé par les tirs de balles venus de la bulle mitoyenne
<p>Additional Waypoints</p>Q14DD74 - Question<br />N 49° 23.826 E 004° 41.752<br />En quelle année François Mitterrand a-t-il terminé son second mandat ?
Le chiffre des dizaines correspond à A.
Un arrêté municipal règlemente l'accès au parc.
Le chiffre représentant le mois correspond à B.<br /></groundspeak:long_description>
<groundspeak:encoded_hints>yucca</groundspeak:encoded_hints>
<groundspeak:logs>
<groundspeak:log id="331961243">
<groundspeak:date>2013-07-21T19:00:00Z</groundspeak:date>
<groundspeak:type>Didn't find it</groundspeak:type>
<groundspeak:finder id="5390315">stefcache</groundspeak:finder>
<groundspeak:text encoded="False">Les coordonnées en poche, direction la cache.
Oh que nous n'aimons pas ces plantes avec quelques piqures, nous abandonnons.</groundspeak:text>
</groundspeak:log>
<groundspeak:log id="328822752">
<groundspeak:date>2013-07-10T19:00:00Z</groundspeak:date>
<groundspeak:type>Found it</groundspeak:type>
<groundspeak:finder id="6269532">paulterguest</groundspeak:finder>
<groundspeak:text encoded="False">petite pause digestive et hop petit tour au parc, je releve les indice et hop direction la cache que je vois de loin... je la camoufle du mieux que je peux pour la faire passer inaperçue! merci pour la cache!</groundspeak:text>
</groundspeak:log>
<groundspeak:log id="327497425">
<groundspeak:date>2013-07-06T13:53:53Z</groundspeak:date>
<groundspeak:type>Found it</groundspeak:type>
<groundspeak:finder id="7183795">gagou52+Alex</groundspeak:finder>
<groundspeak:text encoded="False">Trouvee par ma cherie apres quelques pointes enfoncees dans la peau^^ bravo a elle et MPLC</groundspeak:text>
</groundspeak:log>
<groundspeak:log id="327117020">
<groundspeak:date>2013-07-04T19:00:00Z</groundspeak:date>
<groundspeak:type>Found it</groundspeak:type>
<groundspeak:finder id="7600084">lupauwiltho</groundspeak:finder>
<groundspeak:text encoded="False">pas loin de passer à côté mais trouvé!!!!</groundspeak:text>
</groundspeak:log>
<groundspeak:log id="326420873">
<groundspeak:date>2013-07-01T19:03:43Z</groundspeak:date>
<groundspeak:type>Enable Listing</groundspeak:type>
<groundspeak:finder id="6968858">cachcaillou</groundspeak:finder>
<groundspeak:text encoded="False">c'est reparti</groundspeak:text>
</groundspeak:log>
<groundspeak:log id="319379657">
<groundspeak:date>2013-06-02T19:00:00Z</groundspeak:date>
<groundspeak:type>Found it</groundspeak:type>
<groundspeak:finder id="5589534">Corneliux</groundspeak:finder>
<groundspeak:text encoded="False">Mon premier FTF :-), by night évidemment !
Merci Cachcaillou.
This entry was edited by Corneliux on Sunday, 02 June 2013 at 23:18:39 UTC.</groundspeak:text>
</groundspeak:log>
</groundspeak:logs>
<groundspeak:travelbugs />
</groundspeak:cache>
</wpt>Code : Tout sélectionner
if (file_exists('upload.xml')) {
$xml = simplexml_load_file('upload.xml');
echo $xml->wpt[0]->urlname."->";
echo $xml->wpt[0]['lat']."->";
echo $xml->wpt[0]['lon']."->";
}
Je sais qu'il faut qu'il y ait ces 2 lignes avant le log pour que je le prenne. Donc, en informatique, la condition est :
- SI 2 lignes avant, il y a ça : <groundspeak:type>Found it</groundspeak:type>
- ET SI il y a "Corneliux" dans la ligne d'avant
Mais comment codé ça ! Je n'en ai pas la moindre idée. J'ai essayé d'utiliser Xpath, sans succès, même si je suppute que la solution va venir de côté là.
Si une âme charitable peut m'aider sur ce coup là, ce serait vraiment cool, ça fait des heures que je lis des docs sans succès, please, help...