Salut,
Problème avec l'écriture de fichier XML à chaque fois que j'ajoute les données à XML le fichier écrase le ficher Etudiant.xml et crée un nouveau Etudiant.xml j'utilise l'API JDom
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 import java.io.*; import org.jdom.*; import org.jdom.output.*; public class EnregisterXML { static Element racine = new Element("personnes"); static org.jdom.Document document = new Document(racine); public static void enregistre(String codeC , String nomN , String age){ //On crée un nouvel Element etudiant et on l'ajoute //en temps qu'Element de racine Element etudiant = new Element("etudiant"); racine.addContent(etudiant); Element code = new Element("code"); codeC.setText(codeC); etudiant.addContent(code); Element nom = new Element("nom"); nom.setText(nomN); etudiant.addContent(nom); Element ageA = new Element("age"); ageA.setText(nomN); etudiant.addContent(age); enregistre("Etudiant.xml"); } public static void enregistre(String fichier) { try { XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); sortie.output(document, new FileOutputStream(fichier)); } catch (java.io.IOException e){ } } }
Merci.
Partager