bonjour,

j'ai un fichier xml source ayant cette syntaxe
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
 
<?xml version="1.0" encoding="utf-8"?>
<test>
    <infos>
        <id>1</id>
        <lic>0001</lic>
        <nomprenom>to to</nomprenom>
        <civilite>M</civilite>
        <a>P</a>
        <categorie>x</categorie>
    </infos>
    <infos>
        <id>2</id>
        <lic>0004</lic>
        <nomprenom>ti ti</nomprenom>
        <civilite>f</civilite>
        <a>P</a>
        <categorie>x</categorie>
    </infos>
....
</test>
et je voudrai pour rajouter plusieurs ligne apres
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<categorie>x</categorie>
puis le sauvegarder dans un nouveau fichier
j'utilise phpdocument

le code que j'ai fait
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
 
<?php//appel de la class
$dom = new DomDocument();
 
//chargement du fichier
$dom->load('./xml/infos.xml');
 
$liste_inf_licence = $dom->getElementsByTagName('infos');
 
foreach($liste_inf_licence as $value){
	$categorie = $value->getElementsByTagName('categorie');
 
    $aa = $dom->createElement('total_pf');
	$bb = $dom->createTextNode('test');
	$aa->appendChild($bb);
	$ee = $categorie->item(0);
	$ee->appendChild($aa);
}
$dom->save('./xml/test2.xml');
 
?>
merci beaucoup