Bonjour,
je lis un fichier xml de la forme:
de cette manière:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 <item> <informations> <presentation> <nom>Blabla</nom> <departement>01</departement> </presentation> </informations> </item> <item> <informations> <presentation> <nom>Blublu</nom> <departement>02</departement> </presentation> </informations> </item> <item> <informations> <presentation> <nom>Blablabla</nom> <departement>03</departement> </presentation> </informations> </item>
Je voudrais n'afficher que les items ayant pour département 01 et 02, comment faire?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 <table> <?php // localisation du fichier $mon_fichier = '/home/toto/tableau.xml'; // test de présence du fichier if (file_exists('$mon_fichier')) { $xml = simplexml_load_file('$mon_fichier'); // on commence à lire les informations foreach ($informations->presentation as $item) { echo '<tr> <td>'.$item->nom.'</td> <td>'.$item->departement.'</td></tr> '; } // print_r($xml); } else { exit('Echec lors de l\'ouverture du fichier XML.'); } ?> </table>
a++
Partager