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 26/09/2011, 11h38   #1
Invité de passage
 
Homme
Inscription : août 2011
Messages : 18
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : août 2011
Messages : 18
Points : 1
Points : 1
Par défaut XML > PHP

bonjour,
j'ai un souci au niveau de l'extraction d'un fichier XML vers du PHP
au niveau des accents ,le XML est en "ISO-8859-1" je vous transmet mes deux codes XML et PHP le souci se situ au niveau des accents.
j'arrive a récupérer le titre en "ISO-8859-1" dans "Titre2" mais je n'arrive pas a injecter la valeur en format "ISO-8859-1" dans "deroule2"
pour visualiser le problème vous pouvez mettre un "é" dans le fichier XML dans l’élément administration exemple "Administrationé" et la mon PHP ne fonctionne plus comme je veux

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
 
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<Organigramme>
	<Informations>
	</Informations>
	<Administration_1>
		<Informations>
		</Informations>
		<Direction_1>
			<Informations>
			</Informations>
			<Utilisateur>
				<prenom>prenom1</prenom>
				<nom>nom1</nom>
			</Utilisateur>
			<Utilisateur>
				<prenom>prenom2</prenom>
				<nom>nom2</nom>
			</Utilisateur>
			<Utilisateur>
				<prenom>prenom3</prenom>
				<nom>nom3</nom>
			</Utilisateur>
			<sd1>
				<Utilisateur>
					<prenom>prenom3</prenom>
					<nom>nom3</nom>
				</Utilisateur>
			</sd1>
		</Direction_1>
		<Directeur_1>
			<Informations>
			</Informations>
			<Utilisateur>
				<prenom>prenom4</prenom>
				<nom>nom4</nom>
			</Utilisateur>
		</Directeur_1>
		<Direction_3>
			<Informations>
			</Informations>
			<Directeurs_1>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom5</prenom>
					<nom>nom5</nom>
				</Utilisateur>
			</Directeurs_1>
			<Service_1>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom6</prenom>
					<nom>nom6</nom>
				</Utilisateur>
			</Service_1>
			<Service_2>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom7</prenom>
					<nom>nom7</nom>
				</Utilisateur>
			</Service_2>
			<Service_3>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom8</prenom>
					<nom>nom8</nom>
				</Utilisateur>
			</Service_3>
		</Direction_3>
		<Direction_4>
			<Informations>
			</Informations>
			<Directeurs_1>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom9</prenom>
					<nom>nom9</nom>
				</Utilisateur>
			</Directeurs_1>
			<Service_1>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom10</prenom>
					<nom>nom10</nom>
				</Utilisateur>
			</Service_1>
			<Service_2>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom11</prenom>
					<nom>nom11</nom>
				</Utilisateur>
			</Service_2>
			<Service_3>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom12</prenom>
					<nom>nom12</nom>
				</Utilisateur>
			</Service_3>
		</Direction_4>
		<Pole_1>
			<Informations>
			</Informations>
			<DG_1>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom13</prenom>
					<nom>nom13</nom>
				</Utilisateur>
				<Utilisateur>
					<prenom>prenom14</prenom>
					<nom>nom14</nom>
				</Utilisateur>
			</DG_1>
			<Services_1>
				<Informations>
				</Informations>
				<Utilisateur>
					<prenom>prenom15</prenom>
					<nom>nom15</nom>
				</Utilisateur>
				<Utilisateur>
					<prenom>prenom16</prenom>
					<nom>nom16</nom>
				</Utilisateur>				
			</Services_1>
		</Pole_1>
	</Administration_1>
</Organigramme>
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
 
<meta http-equiv="Content-Type" content="text/html"; charset="ISO-8859-1">
<html>		
	<head>
		<link rel="stylesheet" type="text/css" href="styles.css">
		<title>TEST</title>
	</head>	
	<body bgcolor="#333399">
 
<!------------------------------  CHARGEMENT  XML ------------------------------------------------------>
	<?php 
		$dom = new DOMDocument(); 					
		$dom->load("orgab.xml");		
	?>
<!------------------------------------------------------------------------------------------------------>
 
<!------------------------------------------------------------------------------------------------------>		
	<?php	
		function Titre1 ($dom)
		{
			$parent=$dom->firstChild->nodeName;
			print("<center><font size=\"3\" face=\"Arial\"><b>$parent</b></font></center></br>");
		}	
	?>				
<!------------------------------------------------------------------------------------------------------>		
	<?php
 
		function Deroule1($dom)
		{	
			$parent=$dom->firstChild->nodeName;
			$domliste = $dom->getElementsByTagName($parent); 
			$tab_tag = array();			
			if ($domliste->length == 1)
			{	 
				$elements = $domliste->item(0)->childNodes; 	
				$mon_champ = isset($_POST['mon_champ']) ? $_POST['mon_champ'] : '';
 
 
				foreach ($elements as $node )
				{					
					 if ($node->nodeType == 1) $tab_tag[] = $node->nodeName;
					{
						if( $node->nodeName != "#text" && $node->nodeName != "Informations" && $node->nodeName != "membre_de" )
						{							
							echo '<form action="new1.php" method="post">';
							echo '<input type="submit" name="mon_champ" value="';
							echo utf8_decode($node->nodeName);
							echo '"/></form></center>';	
						}
					}						
				}						
			}	
		}
	?>
<!------------------------------------------------------------------------------------------------------>
	<?php
 
		function Titre2 ($dom)
		{
			if(isset ($_POST['mon_champ'])) 
			{
			$mon_champ =$_POST['mon_champ'];
			}
			echo '<center><font size=\"3\" face=\"Arial\"><b>';
			echo @$mon_champ;
			echo '</b></font></center></br>';
		}
 
	?>
<!------------------------------------------------------------------------------------------------------>
	<?php
 
		function Deroule2($dom)
		{	
 
			if(isset ($_POST['mon_champ'])) 
			{
			$mon_champ =$_POST['mon_champ'];
			}
 
			$domliste = $dom->getElementsByTagName(@$mon_champ); 
			$tab_tag = array();			
			if ($domliste->length == 1)
			{	 
				$elements = $domliste->item(0)->childNodes; 	
				$mon_champ = isset($_POST['mon_champ']) ? $_POST['mon_champ'] : '';
 
 
				foreach ($elements as $node )
				{					
					 if ($node->nodeType == 1) $tab_tag[] = $node->nodeName;
					{
						if( $node->nodeName != "#text" && $node->nodeName != "Informations" && $node->nodeName != "membre_de" )
						{						
							echo '<form action="new1.php" method="post">';
							echo '<input type="submit" name="mon_champ" value="';
							echo utf8_decode($node->nodeName);							
							echo '"/></form></center>';
							if( $node->nodeName == "Utilisateur")
							{
								echo utf8_decode($node->nodeValue);
							}
						}
					}						
				}						
			}
		}
	?>
<!------------------------------------------------------------------------------------------------------>
<!------------------------------------------------------------------------------------------------------>	
<!----------------------       DIV 2           --------------------------------------------------------->
	<div align="center" class="conteneur2"><center></center><div class="bloc2">
		<?php
			Titre1 ($dom);
			Deroule1($dom);
		?>	
	</div></div>
<!------------------------------------------------------------------------------------------------------>
 
<!------------------------------------------------------------------------------------------------------>	
<!----------------------       DIV 3           --------------------------------------------------------->
	<div align="center" class="conteneur3"><center></center><div class="bloc3">
		<?php
			Titre2 ($dom);
			Deroule2($dom);
		?>	
	</div></div>
<!------------------------------------------------------------------------------------------------------>
 
	</body>
</html>
ericdeschamps est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 11h41   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 126
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 126
Points : 8 484
Points : 8 484
php traite (en interne) le XML uniquement en UTF-8
__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 11h54   #3
Invité de passage
 
Homme
Inscription : août 2011
Messages : 18
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : août 2011
Messages : 18
Points : 1
Points : 1
mais comment faire alors ?
quel solution envisager ?
merci d'avance.
ericdeschamps est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 12h02   #4
Modérateur
 
Inscription : septembre 2010
Messages : 7 126
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 126
Points : 8 484
Points : 8 484
qui génère le XML à la base ?
__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 12h17   #5
Invité de passage
 
Homme
Inscription : août 2011
Messages : 18
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : août 2011
Messages : 18
Points : 1
Points : 1
Ce fichier est générer automatiquement par un script, je n'ai pas accès a ce script pour l'instant;
On me la donné comme tel au format XML, je dois l'exploiter et je suis vraiment ennuyer.
Est ce que à la génération du fichier en demandant au script de générer le fichier au format utf-8 la prise en charge des accent sera faite ?
ericdeschamps est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 12h20   #6
Modérateur
 
Inscription : septembre 2010
Messages : 7 126
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 126
Points : 8 484
Points : 8 484
Citation:
Envoyé par ericdeschamps Voir le message
fichier au format utf-8 la prise en charge des accent sera faite ?
oui, enfin si toute ta chaine d'encodage est respecté
__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 12h50   #7
Invité de passage
 
Homme
Inscription : août 2011
Messages : 18
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : août 2011
Messages : 18
Points : 1
Points : 1
une autre question ,je sais je sais j'abuse
tu vois quand je clique j'arrive a descendre dans l'arborescence de mon fichier XML ,mais quand j'arrive au niveau des utilisateur ils s'affichent en ligne continu je voudrais pouvoir filtrer ce contenu et retirer certaine valeur de certains élément pare exemple je voudrais pas qu’apparaisse le contenu de l’élément prénom est ce que tu aurais une idée c'est au niveau de la fonction "Deroule 2"
Code :
1
2
3
4
5
 
if( $node->nodeName == "Utilisateur")
							{
								echo utf8_decode($node->nodeValue);
							}
c'est là que je veux filtrer car il me ramène tout .
ericdeschamps est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/09/2011, 13h08   #8
Modérateur
 
Inscription : septembre 2010
Messages : 7 126
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 126
Points : 8 484
Points : 8 484
utilise Xpath pour obtenir ce que tu souhaites
__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 18h09.


 
 
 
 
Partenaires

Hébergement Web