Suppression noeud XML en PHP

Résolu
Apaachee Messages postés 261 Statut Membre -  
Apaachee Messages postés 261 Statut Membre -
Bonjour,
VOici mon fichier xml :

<Collection>
	<BD>
		<titre>Tintin au tibet</titre>
		<dessinateur>herge</dessinateur>
		<scenariste>herge</scenariste>
		<editeur>nouvelediteur</editeur>
		<serie>Tintin</serie>
		<annee>1782</annee>
	</BD>
	<BD>
...


Et voici mon code php :

$collection = simplexml_load_file("../Information/Collection/".$login.".xml ");

$i=0;
$a = -1;
			
foreach($collection->children() as $bd){
if($collection->BD[$i]->titre == $_GET["titre"] && $collection->BD[$i]->annee == $_GET["annee"])
	$a = $i;
$i++;
}
			
if($a >= -1)
	unset($collection->BD[$a]);



Le $a prend bien la bonne valeur à supprimer mais rien ne se passe avec la fonction unset... Que faire...?
Configuration: Windows Vista
Firefox 3.0.10

1 réponse

  1. Apaachee Messages postés 261 Statut Membre 47
     
    $collection = simplexml_load_file("../Information/Collection/".$login.".xml ");
    
    $i=0;
    $a = -1;
    			
    foreach($collection->children() as $bd){
    if($collection->BD[$i]->titre == $_GET["titre"] && $collection->BD[$i]->annee == $_GET["annee"])
    	$a = $i;
    $i++;
    }
    			
    if($a >= -1){
    	unset($collection->BD[$a]);
            $collection->asXML("../Information/Collection/".$login.".xml ");
    }
    
    


    Oublié de faire un asXML à la fin !!
    0