Bonjour

J'ai un petit soucis de formatage pour un export XML via PHP.
Mon code 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
<?php
 
$db_name = "menu";
$link = mysql_connect("", "", "") or die("Connexion impossible.");
$table_name = 'MENU';
$db = mysql_select_db($db_name, $link);
 
 
$query = "select * from " . $table_name;
$result = mysql_query($query) or die("Impossible d'interroger la base de données");
$num = mysql_num_rows($result);
 
// connaître le nbre de champs
  $nombre=mysql_num_fields($result);
 
// s'il y a des résultats 
if ($num != 0) {
	$file= fopen("phpxml_mnu.xml", "w");
	$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
	$_xml .="<navigation>\r\n";
	while ($row = mysql_fetch_array($result)) {
 
		for ($i=0;$i<$nombre;$i++){    
 
		$champs=mysql_field_name($result,$i);
 
		//convertit en utf8 pour les caractères accentués.
		$contenu=utf8_encode($row[$champs]);
 
            //$_xml .="\t<$champs>" . $contenu . "</$champs>\r\n";   
			$_xml .="\t<menu nom=\"$contenu\" href=\"$contenu\" />\r\n";
  }
         }
$_xml .="</navigation>";
fwrite($file, $_xml); fclose($file);
        echo "Le fichier XML a etait créé <a      href=\"../photos/gallerie.xml\">Show source.</a>";
}
else {
    echo "erreur";
} 
?>

Il me cré un XML comme celui ci
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
 
<?xml version="1.0" encoding="UTF-8" ?>
 
<navigation>
 
	<menu nom="M d'O" href="M d'O" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="Créations" href="Créations" />
 
	<menu nom="Objets" href="Objets" />
 
	<menu nom="Installations" href="Installations" />
 
	<menu nom="Art" href="Art" />
 
	<menu nom="Divers" href="Divers" />
 
	<menu nom="Contacts" href="Contacts" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="Private" href="Private" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
	<menu nom="" href="" />
 
</navigation>
J'aimerai avoir ceci dans l'idée

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="iso-8859-1" ?> 
<navigation>
<menu name="M d'O" href="/home/" />
<menu name="Creations" href="/tutorials/">
	<submenu name="Objets" href="Objets" />
	<submenu name="Instalations" href="Instalations" />
</menu>
<menu name="Contacts" href="/reviews/">
	<submenu name="Books" href="/reviews/books/" />
	<submenu name="Software" href="/reviews/software/" />
</menu>
<menu name="Private" href="/reviews/" />
</navigation>
J'ai fais pas mal de recherches mais je bloque un peu surtout niveau de la syntaxe de la requette.
Merçi d'avance