Bonjour à tous,
Je suis débutant en ce qui concerne l'utilisation d'XPATH en php et je n'arrive pas à faire ce que je veux.
Mon fichier XML :
Et mon bout de php :
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 <?xml version="1.0" encoding="ISO-8859-15"?> <tif:OI xmlns:tif="http://www.tourinfrance.net/Tourinfrance3/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ms="http://microsoft.com/wsdl/types/" xmlns:cs="http://www.enjoyconstellation.com" xmlns:utils="dms-utils" xmlns:media="media-utils"> <tif:Periodes> <tif:DetailPeriode xml:lang="fr" libelle="Manifestation" type="09.01.05"> <tif:Nom xml:lang="fr">PORTES-OUVERTES D'AUTOMNE A TERRE BLANCHE</tif:Nom> <tif:Dates> <tif:DetailDates> <tif:DateDebut>2017-10-28</tif:DateDebut> <tif:DateFin>2017-10-28</tif:DateFin> <tif:Jours> <tif:DetailJours xml:lang="fr" libelle="Ouverture" type="09.03.02"> <tif:Jour xml:lang="fr" libelle="Samedi" lib_jour="09.02.07"> <tif:Horaires><tif:HoraireDebut>14:00</tif:HoraireDebut> <tif:HoraireFin>18:00</tif:HoraireFin> </tif:Horaires> <tif:Horaires><tif:HoraireDebut>10:00</tif:HoraireDebut> <tif:HoraireFin>12:00</tif:HoraireFin> </tif:Horaires> </tif:Jour> </tif:DetailJours> </tif:Jours> </tif:DetailDates> </tif:Dates> </tif:DetailPeriode> <tif:DetailPeriode xml:lang="fr" libelle="Manifestation" type="09.01.05"> <tif:Nom xml:lang="fr">Les rendez-vous gourmands à terre blanche</tif:Nom> <tif:Dates> <tif:DetailDates> <tif:DateDebut>2018-09-01</tif:DateDebut> <tif:DateFin>2018-10-01</tif:DateFin> <tif:Jours> <tif:DetailJours xml:lang="fr" libelle="Ouverture" type="09.03.02"> <tif:Jour xml:lang="fr" libelle="Jeudi" lib_jour="09.02.05"> <tif:Horaires><tif:HoraireDebut>09:00</tif:HoraireDebut> </tif:Horaires> </tif:Jour> </tif:DetailJours> </tif:Jours> </tif:DetailDates> </tif:Dates> </tif:DetailPeriode> </tif:Periodes> </tif:OI>
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 $xml = simplexml_load_file('impt/'.$files[$x]); $xml->registerXPathNamespace('c', 'http://www.tourinfrance.net/Tourinfrance3/'); /* TITRE */ $dctitle = $xml->xpath('/tif:OI/tif:DublinCore/dc:title'); /* DATE DEBUT & FIN */ $DateDebut = $xml->xpath('/tif:OI/tif:Periodes/tif:DetailPeriode/tif:Dates/tif:DetailDates/tif:DateDebut'); $DateFin = $xml->xpath('/tif:OI/tif:Periodes/tif:DetailPeriode/tif:Dates/tif:DetailDates/tif:DateFin');
Comme vous l'aurez compris, le but est de récupérer les bonnes dates (en l’occurrence celles de 2018) et le "NOM" correspondant
Merci !
Partager