Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > XML
XML Forum d'entraide sur XML avec PHP. Exemples : SimpleXML, OpenXML... Avant de poster -> FAQ XML, Cours XML et Sources XML
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/09/2011, 13h13   #1
Invité de passage
 
Inscription : novembre 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 16
Points : 1
Points : 1
Par défaut PB parse fichier xml

Bonjour,

Je viens demander votre aide pour le parse d'un fichier xml qui ne se compose pas de la même façon suivant le critere de vente de bien immobilier.

Pourrier vous me dire comment puis-je faire pour effectuer un OR dans la lecture du fichier.

Je vous montre ci dessous.

Code :
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
 
$xml = read_xml("avhassocies.XML","BIEN",array("TYPE_OFFRE",
											"CODE_SOCIETE",
											"CODE_SITE",
											"NO_ASP",
											"NO_MANDAT",
											"DATE_OFFRE",
											"PRIX",
											"HONORAIRES",
											"CHARGES",
											"DEPOT_GARANTIE",
											"TAXE_FONCIERE",
											"CP_INTERNET",
											"VILLE_INTERNET",
											"QUARTIER",
											"SECTEUR",
											"CATEGORIE",
											"NB_PIECES",
											"NB_CHAMBRES",
											"SURF_HAB",
											"SURF_CARREZ",
											"SURF_SEJOUR",
											"SURF_TERRAIN",
											"ETAGE",
											"NB_ETAGES",
											"ANNEE_CONS",
											"CUISINE",
											"NB_WC",
											"NB_SDB",
											"NB_SE",
											"NB_PARK_INT",
											"GARAGE_BOX",
											"SOUS_SOL",
											"TYPE_CHAUFF",
											"NATURE_CHAUFF",
											"ASCENSEUR",
											"BALCON",
											"TERRASSE",
											"PISCINE",
											"ACCES_HANDI",
											"MURS_MITOYENS",
											"TEXTE_FR",
											"RS_AGENCE",
											"ADRESSE1_AGENCE",
											"ADRESSE2_AGENCE",
											"CP_AGENCE",
											"VILLE_AGENCE",
											"TEL_AGENCE",
											"FAX_AGENCE",
											"MAIL_AGENCE",
											"INFO_TERRASSE",
											"INFO_BALCON",
											"DISPO",
											"LOYER2",
											"DATE_LIBER",
											"NET_VENDEUR",
											"HONO_ACQ",
											"SURF_JARDIN",
											"DPE_ETIQ1",
											"DPE_ETIQ2",
											"DPE_VAL1",
											"DPE_VAL2",
											"INFO_KM",
											"NB_NIVEAUX",
											"CESSIONDROITAUBAIL",
											"LONGUEURVITRINE",
											"INTERPHONE",
											"MONTECHARGE",
											"IMMEUBLEINDEPENDANT",
											"IMMEUBLECOLLECTIF",
											"IMMEUBLEPRESTIGE",
											"CLIMATISATION",
											"SURFACEPROFESSIONNELLE",
											"SURFACEANNEXE",
											"SURFACELOGEMENT",
											"LOYER"));
 
foreach($xml as $row) {
La case "PRIX" est quelques fois en "LOYER".

Comment faire ?

Merci pour votre aide
xyrox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/09/2011, 21h02   #2
Expert Confirmé
 
Avatar de Séb.
 
Inscription : mars 2005
Messages : 2 823
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France

Informations professionnelles :
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : mars 2005
Messages : 2 823
Points : 3 454
Points : 3 454
J'ai lu et n'ai pas compris le problème
__________________
Un problème exposé clairement est déjà à moitié résolu
Keep It Smart and Simple
Séb. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/09/2011, 21h47   #3
Invité de passage
 
Inscription : novembre 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 16
Points : 1
Points : 1
la plus part du temps la case PRIX de mon array $row[6] à la valeur de prix, jusque la c'est logique. Mais dès fois lors de la mise en tableau de mon xml la case PRIX se nomme LOYER du coup sa marche pas ma case $row[6] est vide.

Je sais pas trop comme faire pour inclure LOYER dans mon array
xyrox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/09/2011, 23h54   #4
Membre du Club
 
Inscription : novembre 2006
Messages : 85
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 85
Points : 63
Points : 63
Déjà tout dépends de comment la fonction read_xml parse ton xml.

Sinon a la fin de ton script, tu peux retraiter pour lire ton index de tableau correspondant à PRIX et si celui de LOYER $row[6] est vide, alors tu l'affecte depuis celui de PRIX.
sjachym est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/09/2011, 18h46   #5
Invité de passage
 
Inscription : novembre 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 16
Points : 1
Points : 1
Ha oui j'avais pas pensé à sa. merci je vais essayer et désolé pour le up ^^
xyrox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/09/2011, 09h25   #6
Invité de passage
 
Inscription : novembre 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 16
Points : 1
Points : 1
Je ne trouve toujours pas comment faire.
Je vous met en code l’intégralité du mon script dès fois que vous aillez une idée sur la question.

Code :
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
function read_xml($fichier,$item,$champs) {
   // on lit le fichier
   if($chaine = @implode("",@file($fichier))) {
      // on explode sur <item>
      $tmp = preg_split("/<\/?".$item.">/",$chaine);
      // pour chaque <item>
      for($i=1;$i<sizeof($tmp)-1;$i+=2)
         // on lit les champs demandés <champ>
         foreach($champs as $champ) {
            $tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);
            // on ajoute l'élément au tableau
            $tmp3[$i-1][] = @$tmp2[1];
         }
      // et on retourne le tableau dans la fonction
      return $tmp3;
   }
}
 
// Lecture du FLUX XML sur le serveur
$xml = read_xml("avhassocies.XML","BIEN",array("TYPE_OFFRE",
											"CODE_SOCIETE",
											"CODE_SITE",
											"NO_ASP",
											"NO_MANDAT",
											"DATE_OFFRE",
											"PRIX",
											"HONORAIRES",
											"CHARGES",
											"DEPOT_GARANTIE",
											"TAXE_FONCIERE",
											"CP_INTERNET",
											"VILLE_INTERNET",
											"QUARTIER",
											"SECTEUR",
											"CATEGORIE",
											"NB_PIECES",
											"NB_CHAMBRES",
											"SURF_HAB",
											"SURF_CARREZ",
											"SURF_SEJOUR",
											"SURF_TERRAIN",
											"ETAGE",
											"NB_ETAGES",
											"ANNEE_CONS",
											"CUISINE",
											"NB_WC",
											"NB_SDB",
											"NB_SE",
											"NB_PARK_INT",
											"GARAGE_BOX",
											"SOUS_SOL",
											"TYPE_CHAUFF",
											"NATURE_CHAUFF",
											"ASCENSEUR",
											"BALCON",
											"TERRASSE",
											"PISCINE",
											"ACCES_HANDI",
											"MURS_MITOYENS",
											"TEXTE_FR",
											"RS_AGENCE",
											"ADRESSE1_AGENCE",
											"ADRESSE2_AGENCE",
											"CP_AGENCE",
											"VILLE_AGENCE",
											"TEL_AGENCE",
											"FAX_AGENCE",
											"MAIL_AGENCE",
											"INFO_TERRASSE",
											"INFO_BALCON",
											"DISPO",
											"LOYER2",
											"DATE_LIBER",
											"NET_VENDEUR",
											"HONO_ACQ",
											"SURF_JARDIN",
											"DPE_ETIQ1",
											"DPE_ETIQ2",
											"DPE_VAL1",
											"DPE_VAL2",
											"INFO_KM",
											"NB_NIVEAUX",
											"CESSIONDROITAUBAIL",
											"LONGUEURVITRINE",
											"INTERPHONE",
											"MONTECHARGE",
											"IMMEUBLEINDEPENDANT",
											"IMMEUBLECOLLECTIF",
											"IMMEUBLEPRESTIGE",
											"CLIMATISATION",
											"SURFACEPROFESSIONNELLE",
											"SURFACEANNEXE",
											"SURFACELOGEMENT"));
 
foreach($xml as $row) {
 
	$dirimg = "../annonce/";
	$type = $row[0];
	$mandat = $row[4];
	$date_offre = $row[5];
	$prix = $row[6];
	$loyer = $row[73];
	$honoraire = $row[7];
	$charge = $row[8];
	$garantie = $row[9];
	$taxe_fonciere = $row[10];
	$cp = $row[11];
	$dep = substr($row[11],0,2);
	$ville = $row[12];
	$quartier = $row[13];
	$secteur = $row[14];
	$categ = $row[15];
	$piece = $row[16];
	$chambre = $row[17];
	$surface_hab = $row[18];
	$surface_carrez = $row[19];
	$surface_sej = $row[20];
	$surface_terrain = $row[21];
	$etage = $row[22];
	$nb_etage = $row[23];
	$annee_const = $row[24];
	$cuisine = addslashes($row[25]);
	$nb_wc = $row[26];
	$nb_sb = $row[27];
	$nb_se = $row[28];
	$nb_park_int = $row[29];
	$garage_box = $row[30];
	$sous_sol = $row[31];
	$type_chauffage = $row[32];
	$nature_chauffage = $row[33];
	$assenceur = $row[34];
	$balcon = $row[35];
	$terrasse = $row[36];
	$piscine = $row[37];
	$acces_handi = $row[38];
	$mur_mit = $row[39];
	$com = mysql_real_escape_string(strip_tags($row[40]));
	$rs_ag = $row[41];
	$adresse_ag_1 = $row[42];
	$adresse_ag_2 = $row[43];
	$cp_ag = $row[44];
	$ville_ag = $row[45];
	$tel_ag = $row[46];
	$fax_ag = $row[47];
	$mail_ag = $row[48];
	$info_terrasse = $row[49];
	$info_balcon = $row[50];
	$dispo = $row[51];
	$loyer2 = $row[52];
	$date_liber = $row[53];
	$net_vendeur = $row[54];
	$hoho_acq = $row[55];
	$surf_jardin = $row[56];
	$dpe_etiqu1 = $row[57];
	$dpe_etiqu2 = $row[58];
	$dpe_val1 = $row[59];
	$dpe_val2 = $row[60];
	$info_km = $row[61];
	$nb_niveau = $row[62];
	$cession_droit_au_bail = $row[63];
	$longueur_vitrine = $row[64];
	$interphone = $row[65];
	$monte_charge = $row[66];
	$immeuble_independant = $row[67];
	$immeuble_prestige = $row[68];
	$clim = $row[69];
	$surface_pro = $row[70];
	$surface_annexe = $row[71];
	$surface_logement = $row[72];
 
	if (empty($prix)){
		$prix = $loyer;
	}
 
 	if ("1" == $piece){
		$piece = "t1";
	}elseif ("2" == $piece){
		$piece = "t2";
	}elseif ("3" == $piece){
		$piece = "t3";
	}elseif ("4" == $piece){
		$piece = "t4";
	}elseif ($piece >= "5"){
		$piece = "t5+";
	}
	if (empty($piece)){
		$piece = "autre";
	}
 
  	if ("1" == $type){
		$titre_type = "Vente appartement";
		$type_ann = "vente";
	}elseif("2" == $type){
		$titre_type = "Vente maison";
		$type_ann = "vente";
	}elseif("3" == $type){
		$titre_type = "Vente terrain";
		$type_ann = "vente";
	}elseif("4" == $type){
		$titre_type = "Vente immeuble";
		$type_ann = "vente";
	}elseif("5" == $type){
		$titre_type = "Vente local";
		$type_ann = "vente";
	}elseif("6" == $type){
		$titre_type = "Vente FDC";
		$type_ann = "vente";
	}elseif("7" == $type){
		$titre_type = "Vente parking";
		$type_ann = "vente";
	}elseif("11" == $type){
		$titre_type = "Location appartement";
		$type_ann = "location";
	}elseif("12" == $type){
		$titre_type = "Location maison";
		$type_ann = "location";
	}elseif("13" == $type){
		$titre_type = "Location local";
		$type_ann = "location";
	}elseif("14" == $type){
		$titre_type = "Location parking";
		$type_ann = "location";
	}else{
		$titre_type = "Autres";
		$type_ann = "autres";
	}
 
	if ("MAS" == $categ){
		$categorie = "maison";
	}elseif ("MAISON DE VILLAGE" == $categ){
		$categorie = "maison";
	}elseif ("MAISON DE VILLE" == $categ){
		$categorie = "maison";
	}elseif ("PAVILLON" == $categ){
		$categorie = "maison";	
	}elseif ("PAVILLON CONTEMPORAIN" == $categ){
		$categorie = "maison";	
	}elseif ("MAISON CONTEMPORAINE" == $categ){
		$categorie = "maison";	
	}elseif ("FERMETTE" == $categ){
		$categorie = "maison";
	}elseif ("MAISON DE PIERRE" == $categ){
		$categorie = "maison";
	}elseif ("MAISON DE BOURG" == $categ){
		$categorie = "maison";
	}elseif ("MAISON BOURGEOISE" == $categ){
		$categorie = "maison";
	}elseif ("LONGERE" == $categ){
		$categorie = "maison";
	}elseif ("VILLAS" == $categ){
		$categorie = "maison";
	}elseif ("VILLA" == $categ){
		$categorie = "maison";
	}elseif ("APPARTEMENT" == $categ){
		$categorie = "appartement";
	}elseif ("STUDIO" == $categ){
		$categorie = "appartement";
	}elseif ("STUDIO MEUBLE" == $categ){
		$categorie = "appartement";
	}elseif ("IMMEUBLE VIDE" == $categ){
		$categorie = "appartement";
	}elseif ("IMMEUBLE A DECOUPER" == $categ){
		$categorie = "appartement";
	}elseif ("IMMEUBLE LOUE" == $categ){
		$categorie = "appartement";
	}elseif ("IMMEUBLE DE RAPPORT" == $categ){
		$categorie = "appartement";
	}elseif ("Chalet" == $categ){
		$categorie = "appartement";
	}elseif ("BATIMENT A RESTAURER" == $categ){
		$categorie = "appartement";
	}elseif ("BATIMENT EN PIERRE" == $categ){
		$categorie = "appartement";
	}elseif ("TERRAIN" == $categ){
		$categorie = "terrain";
	}elseif ("TERRAIN À BATIR" == $categ){
		$categorie = "terrain";
	}elseif ("TERRAIN CONSTRUCTIBLE" == $categ){
		$categorie = "terrain";
	}elseif ("TERRAIN AGRICOLE" == $categ){
		$categorie = "terrain";
	}else{
		$categorie = "autre";
	}
 
	$titre = $categ." en ".$type_ann." dans le ".$dep;
	$titre = mysql_real_escape_string(strip_tags($titre));
 
	$img1 = $row[1]."-".$row[2]."-".$row[3]."-a.jpg";
	$dirimg1 = $dirimg."".$img1;
	if (!file_exists($dirimg1)){
		$img1 = "nophoto.png";
	}
	$img2 = $row[1]."-".$row[2]."-".$row[3]."-b.jpg";
	$dirimg2 = $dirimg."".$img2;
	if (!file_exists($dirimg2)){
		$img2 = "nophoto.png";
	}
 
	$img3 = $row[1]."-".$row[2]."-".$row[3]."-c.jpg";
	$dirimg3 = $dirimg."".$img3;
	if (!file_exists($dirimg3)){
		$img3 = "nophoto.png";
	}
 
	$img4 = $row[1]."-".$row[2]."-".$row[3]."-d.jpg";
	$dirimg4 = $dirimg."".$img4;
	if (!file_exists($dirimg4)){
		$img4 = "nophoto.png";
	}
 
	$adannonce = mysql_query ("SELECT * FROM annonce WHERE mandat='".$manda."'");
 
	if (0 == mysql_num_rows($adannonce)){
		$insert = "INSERT INTO annonce VALUES('','$type_ann','$titre_type','$titre','$com','$mandat','$date_offre','$prix','$honoraire','$charge','$garantie','$taxe_fonciere','$cp','$dep','$ville','$quartier','$secteur','$categ','$categorie','$piece','$chambre','$surface_hab','$surface_carrez','$surface_sej','$surface_terrain','$etage','$nb_etage','$annee_const','$cuisine','$nb_wc','$nb_sb','$nb_se','$nb_park_int','$garage_box','$sous_sol','$type_chauffage','$nature_chauffage','$assenceur','$balcon','$terrasse','$piscine','$acces_handi','$mur_mit','$rs_ag','$adresse_ag_1','$cp_ag','$ville_ag','$tel_ag','$fax_ag','$mail_ag','$info_terrasse','$info_balcon','$dispo','$loyer2','$date_liber','$net_vendeur','$hono_acq','$surface_jardin','$dpe_etique1','$dpe_etique2','$dpe_val1','$dpe_val2','$info_km','$nb_niveau','$cession_droit_au_bail','$longueur_vitrine','$interphone','$monte_charge','$immeuble_independant','$immeuble_prestige','$clim','$surface_pro','$surface_annex','$surface_logement','$img1','$img2','$img3','$img4')";
		if (!mysql_query($insert)){						
			echo "<p>$mandat - Un problème est survenu lors de l'enregistrement.</p>";
			echo mysql_error(mysql_connect($db_host,$db_user,$db_pass));
		}
		$nb++;
	}
 
}
Merci pour votre aide
xyrox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/09/2011, 17h36   #7
Invité de passage
 
Inscription : novembre 2006
Messages : 16
Détails du profil
Informations forums :
Inscription : novembre 2006
Messages : 16
Points : 1
Points : 1
Je n'ai toujours pas trouvé comment faire. J'ai refais mon script de différente manière mais jamais la bonne solution.
xyrox est déconnecté   Envoyer un message privé Réponse avec citation 01
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h40.


 
 
 
 
Partenaires

Hébergement Web