Bonjour,
Jai créé un script pour modifier un fichier xml a un certain endroit mais ca marche pas et je voie pas où est l'erreur pourriez vous m'aider merci
Fichier XML :
<galerie>
<photo>
<nom>grenou.jpg</nom>
<description>
<date>26/02/2006</date>
<evenement>bapteme</evenement>
<protagoniste>
<personnage>Mamie</personnage>
</protagoniste>
</description>
</photo>
</galerie>
Script PHP :
function modifxml($nomphoto,$date,$evenement,$personnage,$fichier_xml)
{
$modif = new DomDocument;
//Permet de créer les différents noeud pour les nouvelles photo.
$newphoto = $modif->createElement('photo');
$newnom = $modif->createElement('nom',$nomphoto);
$newdescription = $modif->createElement('description');
$newdate = $modif->createElement('date',$date);
$newevenement = $modif->createElement('evenement',$evenement);
$newprotagoniste = $modif->createElement('protagoniste');
//Boucle permettant l'ajout de plusieurs personnage.
foreach($personnage as $element)
{
$newpersonnage = $modif->createElement('personnage',$element);
$newprotagoniste->appendChild($newpersonnage);
}
//Permet d'ajouter les nouveau fils à la fin des fils.
//$galerie->appendChild($newphoto);
$newphoto->appendChild($newnom);
$newphoto->appendChild($newdescription);
$newdescription->appendChild($newdate);
$newdescription->appendChild($newevenement);
$newdescription->appendChild($newprotagoniste);
//creation obj DOM
$doc = new DOMDocument;
//charge fichier xml d'origine
$doc->load($fichier_xml);
//creation obj DOM xpath
$doc_xpath = new DOMXPath($doc);
//recherche par xpath du noeud a supprimer (normalement une seule reponse)
$entries=$doc_xpath->query('photo[nom="'.$nomphoto.'"]');
//on selectionne la reponse
$oldnode=$entries->item(0);
// Load the $parent document fragment into the current document
$newnode = $doc->importNode($modif->documentElement, true);
// Replace
$oldnode->parentNode->replaceChild($newnode, $oldnode);
//enregistrement du fichier
$doc->save($fichier_xml);
}
$perso = array('pierre','paul','jacque','milouse');
modifxml('grenou.jpg','12/05/2006','Vacance',$perso,'galerie_test.xml');
merci