Je dois travailler avec un api soap, j'arrive à récupérer des données dans le navigateur mais celui ci n'est pas sous forme de tableau donc je n'arive pas à extraire les données entre les balises .
J'ai beau essayé simplexml mais ca me retourne tjs une variable vide .
J'ai essayé beaucoup de solution mais la je sècheNom : curl-ifce.png
Affichages : 408
Taille : 73,4 KoNom : curl-ifce.png
Affichages : 408
Taille : 73,4 KoNom : curl-ifce.png
Affichages : 408
Taille : 73,4 Ko

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
$url='http://wsdnarec.haras-nationaux.fr/dnaservices/DiffusionServices';
 
$curl = curl_init();
 
curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_USERNAME=>'labeo',
  CURLOPT_PASSWORD=>'78t!m#0.',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
 
  CURLOPT_TIMEOUT => 30,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webServices.server.ifce.fr/">
 <soapenv:Header/>
 <soapenv:Body>
 <web:getInformationPreleveur>
 <!--Optional:-->
 <infoPreleveurIn>
 <!--Optional:-->
 <contextHn>
 <!--Optional:-->
 <isoLangage>EN</isoLangage>
 <!--Optional:-->
 <utilisateurID>LABEO</utilisateurID>
 <!--Optional:-->
 <applicationID>WSDNA</applicationID>
 </contextHn>
 <!--Optional:-->
 <identID>526797</identID>
 <!--Optional:-->
 <identKey>T</identKey>
 </infoPreleveurIn>
 </web:getInformationPreleveur>
 </soapenv:Body>
</soapenv:Envelope>',
  CURLOPT_HTTPHEADER => array(
 
//-----------------------------------pas de reponse--------------------------//
    // 'Content-Type: application/xml; charset=utf-8'
    // 'Content-Type: application/xml'
     // 'Content-Type: multipart/form-data'
    // 'Content-Type:soap+xml'
 
    //--------------------------------reponse-----------------------//
    // 'Content-type: text/xml' 
    'Content-Type:application/soap+xml'
  ),
));
 
$response = curl_exec($curl);
 
$err=curl_error($curl);
 
 
 
echo "reponse avec response curl exec:$response";
 
echo '<br><br><br>';
 
$res= htmlspecialchars($response);//htmlspecialchars permets de transformer en XML
echo"reponse avec htlmspecialchars: $res ";
 
echo '<br><br><br>';
 
// $ifce=simplexml_load_string($response);
// print_r($ifce);
// var_dump($ifce);
 
 
$xml=simplexml_load_string($response);
echo "reponse avec simplexml_load_string: $xml";
// echo $xml->Body. "<br>";
 
// ------------------------------------1 er essai--------------------------//
 
// $ip=
// 	$response->children("http://schemas.xmlsoap.org/soap/envelope/")// <env:*>
 
//   ->children("http://webServices.server.ifce.fr/") // <ns2:*>
//   ->body; // <env:body>
// 	$response->getInformationPreleveurResponse // <ns2:getInformationPreleveurResponse>
// 	// ->children("http://schemas.xmlsoap.org/soap/envelope/"); // <*>
//   ->informationPreleveur; // <informationPreleveur>
 
// echo (string)$ip->adresse1; // 4 PLACE DE L'EGLISE
 
 
 
//-------------------------------------------2 eme essai------------------------------------//
 
// 1- <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
// $envelope = $ifce ->children("http://schemas.xmlsoap.org/soap/envelope/");
//   echo"$ envelope: $envelope";
 
//2- <env:Body>
// $Body=$envelope->Body;
// echo "$ body : $Body";
 
// //3-<ns2:getInformationPreleveurResponse xmlns:ns2="http://webServices.server.ifce.fr/">
//   $ns2=$Body->children("http://webServices.server.ifce.fr/");
//   echo "$ ns2: $ns2";
//   $getInformationPreleveurResponse=$ns2->getDataResponse;
//   echo "$ getinformationPreleveurResponse: $getInformationPreleveurResponse";
 
// //4-  <informationPreleveur>
// $default=$getInformationPreleveurResponse;
// echo "$ defaut: $default";
// $informationPreleveur=$default->informationPreleveur;
// echo "$ informationPreleveur: $informationPreleveur";
 
// //5- <adresse1>
// $adresse1 = $informationPreleveur->adresse1;
// echo "adresse1 : $adresse1";
 
// var_dump($response);// affiche string (676) + la chaine de caractère 
// echo "reponse avec $ reponse :$response"; // affiche la chaine de caractère 
 
//---------------------------------------------------------------------------------------------------------------//
echo '<br><br><br>';
// $xml = simplexml_load_file( htmlspecialchars($response)); //htmlspecialchars permets de transformer en XML
// $res= htmlspecialchars($response);
// echo"reponse $ res: $res ";
 
 
// $homepage = file_get_contents($response);
 
 
    //tu peux accéder aux éléments comme ça: (un élément est défini par <qqch>element</qqch>
    // foreach( $res as $element ) 
    // { 
    //     print_r( $element ); 
    // } 
 
    // echo '<br><br><br>';
    // $xml =simplexml_load_file($res);
    // echo $xml;
//----------------------------------recuperation données---------------------------------//
// public SoapClient::__construct($response);
//--------------------------------------------encodage------------------------------------//
 
 
 
// var_dump(json_decode($response)) ; // reponse :null
 
 
// problème, il affiche également le status 200 même si erreur dans l'identKey
// var_dump(http_response_code());//affichage du code erreur
 
 
// $xml = simplexml_load_file($response);
// $appel=$xml;
// echo $appel;
 
// echo($xml);
// var_dump($response);
 
 
 
//-------------------------------------------------coupure chaine--------------------------------//
 
// $truc= htmlspecialchars("<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><ns2:getInformationPreleveurResponse xmlns:ns2=\"http://webServices.server.ifce.fr/\"><informationPreleveur><adresse1>4 PLACE DE L'EGLISE</adresse1><civilite>MME</civilite><codePostal>62128</codePostal><commune>CROISILLES</commune><dateDebutFonction>2013-11-14</dateDebutFonction><mail>72880@ifce.fr</mail><nom>GENTY</nom><nuIdentificateur>526797</nuIdentificateur><nuperso>72880</nuperso><prenom>ANNE</prenom><telFixe>+33 (0)555555555</telFixe><telPortable>+33 (0)606060606</telPortable></informationPreleveur></ns2:getInformationPreleveurResponse></env:Body></env:Envelope>");
// echo"response h t m l : $truc";
// echo '<br><br><br>';
 
 
 
// $Search = "telPortable";
// echo $Search;
 
 
//----------------------------------------------------------------------------//
 
// $IndexDebut = strpos($truc,$Search);
// echo "index debut :$IndexDebut";
 
//-----------------------------------coupure caractères--------------------------------------------//
 
 
// $Longueur = strlen($xml) - strpos($xml,$Search );
// echo " longueur donnée recherchée $Longueur";
 
// echo ("</".$Search);
 
 
//deconne à partir de là
// $Resultat = substr($xml,$IndexDebut,$Longueur);
// echo $Resultat;
 
// $Resultats = substr($Resultat,0,strpos($Resultat,"<"));
 
// echo $Resultats;
 
//-------------------------------------------------------------------------------------------------------//
 
// $result  =  simplexml_load_file ( $response );
// $solution= $result->informationpreleveur[0]-> adresse1;
// echo $solution;
 
// $sxml = simplexml_load_file($response );
 
// echo $sxml->adresse1;
 
// $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
// $xml = new SimpleXMLElement($response);
// $body = $xml->xpath('//SBody')[0];
// $array = json_decode(json_encode((array)$body), TRUE); 
// print_r($array);
 
// -------------------------------------------dernier essai------------------------------------------------------------------------------------------------//
// $movies = new SimpleXMLElement($response);
// echo"réponse avec SimpleXMLElement : $movies";
// echo $movies->informationPreleveur->adresse1;
 
 
curl_close($curl);
 
 ?>