[DOM] Création et insertion d'un élément
Bonjour à tous,
J'essaye depuis hier d'ajouter dans mon fichier XML un nouveau noeud, mais je suis dans l'impasse.
Mon fichier xml se structure de la manière suivante :
Code:
1 2 3 4 5 6 7
|
<dic>
<word>
<fr>mot</fr>
<en>word</en>
</word>
</dic> |
Lorsque j'ajoute un noeud avec ce code ci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//création d'un noeud
$root = $this->domxml->createElement('word');
$root = $this->domxml->appendChild($root);
//créer une fonction qui recherche tous les id
$root->setAttribute("id", 36);
$fr = $this->domxml->createElement('fr');
$fr = $root->appendChild($fr);
$text = $this->domxml->createTextNode($insert);
$text = $fr->appendChild($text);
//Sauvegarde dans le fichier
$this->domxml->save($this->filexml); |
cela me créé mon nouveau noeud mais à la fin de mon fichier xml.
Moi je souhaiterais qu'il se trouve dans la balise <dic>
Comment dois-je m'y prendre ?