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
| public void enregistre(final String fichier)
{
int i;
int nbr;
String value;
final Element racine = new Element(treePanel.treeModel.getRoot().toString());
// On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer //
final org.jdom.Document document = new Document(racine);
nbr = treePanel.rootNode.getChildCount();
for (i=0; i< nbr; i++)
{
AutoElement libelle = new AutoElement();
libelle.setText(treePanel.rootNode.getChildAt(i).toString());
// c'est simplement ça
toXMLElement(treePanel.rootNode.getChildAt(i), treePanel.treeModel, libelle);
racine.addContent(libelle);
}
try
{
// Affichage classique avec getPrettyFormat() //
final XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
//Création du fichier
sortie.output(document, new FileOutputStream(fichier));
}
catch (final java.io.IOException e){}} |
Partager