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
| public static void main (String[] args){
try{
//mettre en paramètre le contenu du bouton Parcourir de pageModif.jsp
lireFichier("G:\\testeur.xml");
addElement("intitule");
enregistreFichier("G:\\testeur.xml");
}
catch(Exception e){
System.out.println(e);
}
}
static void lireFichier(String fichier) throws Exception{
SAXBuilder sxb = new SAXBuilder();
document = sxb.build(new File("G:\\testeur.xml"));
racine = document.getRootElement();
}
static void addElement(String element){
List list = racine.getChildren("type");
Iterator i = list.iterator();
Element courant = (Element)i.next();
// mettre en paramètre le contenu de la zone de saisie de pageModif.jsp
Element nouveau1=new Element ("intitule");
courant.addContent(nouveau1);
}
static void enregistreFichier(String fichier) throws Exception
{
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
sortie.output(document, new FileOutputStream("G:\\testeur.xml"));
}
} |