bonjour à tous, j'ai un petit soucis

voila je charge le contenu d'un fichier XML dans un tableau, pour effectué des manipulation, et ensuite rebasculé en XML le tableau.

mon tableau associatif que je génére est de la forme :

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
Array
(
    [song] => Array
        (
            [id_song=5089] => Array
                (
                    [title] => Let It Be
                    [artist] => The Beatles
                    [date_added] => 2006-01-04
                    [date_update] => 2006-01-09
                    [file] => Array
                        (
                            [id_file=134] => Array
                                (
                                    [track_type] => 
                                    [crc32] => 
                                    [size] => 
                                )
 
                        )
 
                )
 
            [id_song=5090] => Array
                (
                    [title] => Là-bas
                    [artist] => Jean-Jacques Goldman
                    [date_added] => 2006-01-05
                    [date_update] => 2006-04-27
                    [file] => Array
                        (
                            [id_file=135] => Array
                                (
                                    [track_type] => Instrumental
                                    [crc32] => 3283162284
                                    [size] => 6081434
                                )
 
                        )
 
                )
         )
)
j'aimerais re-parcourir ce tableau est obtenir ceci :

<song id_song="5089">
<title>Let It Be</title>
<artist>The Beatles</title>
<date_added>2006-01-04</date_added>
<date_update>2006-01-09</date_update>
<file id_file="134">
<track_type></track_type>
<crc32></crc32>
<size></size>
</file>
</song>
<song id_song="5090">
<title>Là-bas</title>
<artist>Jean-Jacques Goldman</title>
<date_added>2006-01-05</date_added>
<date_update>2006-04-27</date_update>
<file id_file="135">
<track_type>Instrumental</track_type>
<crc32>3283162284</crc32>
<size>6081434</size>
</file>
</song>
les keys "id_song=xxx" et "id_file=xxx" sont en fait les attribut respectif des noeuds <song> et <file> c'est pour moi modifier plus facilement une valeur dans le tableau sachant que le id_song = à autant.

ma fonction :

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
function arrayToXML($array)
{
global $str;
foreach($array as $k => $v)
{
   if(is_array($v))
   {	
      list($attrName, $attrValue) = split("=",$k);
	  if($attrName <> "" && $attrValue <> "")
	  {
	    $node = split("_",$attrName);
	    $node = $node[1];
	    $str .= htmlentities("<$node $attrName=\"$attrValue\">")."<br>";
	  }
     arrayToXML($v);
     }
      else
	 $str .= htmlentities("<$k>$v</$k>")."<br>";
}
}
mon echo $str en sorti donne ceci :

<song id_song="5089">
<title>Let It Be</title>
<artist>The Beatles</artist>
<date_added>2006-01-04</date_added>
<date_update>2006-01-09</date_update>
<file id_file="134">
<track_type></track_type>
<crc32></crc32>
<size></size>

<song id_song="5090">
<title>Là-bas</title>
<artist>Jean-Jacques Goldman</artist>
<date_added>2006-01-05</date_added>
<date_update>2006-04-27</date_update>
<file id_file="135">
<track_type>Instrumental</track_type>
<crc32>3283162284</crc32>
<size>6081434</size>
comme vous pouvez le remarquer je ne trouve pas l'astuce, pour fermer les noeuds contenant des enfants, comme <song> ou encore <file>

auriez vous une idée ?

merci d'avance !