Bonjour,
J’ai un souci pour extraire les données d’un flux xml que je reçois :
Pour exemple et pour simplifier, voici un fichier de structure identique (mais allégé ici)
Je reçois donc ceci.
si je simplifie mon fichier comme ça :
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 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <ListCarsResponse xmlns="http://blablabla.com/webservices/"> <ListCarsResult> <CAR_list xmlns="http://blablabla.com/webservices/CAR_list.xsd"> <Product ProductId="13956" provider="MySelf" name="Peugeot" type="106"> <ColorType productId="13956;19630" name="Black"> </ColorType> </Product> <Product ProductId="22568" provider="MySelf" name="Peugeot" type="406"> <ColorType productId="22568;24575" name="Red"> </ColorType> </Product> </CAR_list> </ListCarsResult> </ListCarsResponse> </soap:Body> </soap:Envelope>
alors avec quelques « foreach », je récupere ce que je veux ..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?xml version="1.0" encoding="utf-8"?> <CAR_list xmlns="http://blablabla.com/webservices/CAR_list.xsd"> <Product ProductId="13956" provider="MySelf" name="Peugeot" type="106"> <ColorType productId="13956;19630" name="Black"> </ColorType> </Product> <Product ProductId="22568" provider="MySelf" name="Peugeot" type="406"> <ColorType productId="22568;24575" name="Red"> </ColorType> </Product> </CAR_list>
Mais comment faire face à la structure que je reçois ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 $Product = $xml->xpath('//Product'); foreach ($xml as $Product) { echo $Product['ProductId']."<BR>"; echo $Product['name']."<BR>"; echo $Product['type']."<BR>"; foreach ($Product as $ColorType) { echo $ColorType['productId']."<BR>"; echo $ColorType['name']."<BR>"; } }
A cause notamment des « : » dans le tag de « Body » ou celui d’ « Envelop » je n’arrive pas a exprimer mon xpath.
Quelqu’un a-t-il une solution ??
Merci d’avance
Paulux1
Partager