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 44 45 46 47 48 49 50
   | package alouha;
 
	import java.io.*;
	import org.jdom.*;
	import org.jdom.output.*;
	import java.text.Format;
 
	public class JDOM1 {                                                                                                                                   
	 static Element racine = new Element("personnes");
	*
	static org.jdom.Document document = new Document(racine);                         	                                                                                        
	   public static void main(String[] args)                                  
	   {                                                                                                                                   
	Element etudiant = new Element("etudiant");
	 racine.addContent(etudiant); *
	 Attribute classe = new Attribute("classe","P2"); 
	etudiant.setAttribute(classe);                                  
	Element nom = new Element("nom");                         
	  nom.setText("CynO");                                                                  
	   etudiant.addContent(nom);
 
	      affiche();
	      enregistre("Exercice1.xml");
	   }
 
	   static void affiche()
	   {
	      try
	      {
 
	         XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
	         sortie.output(document, System.out);
	      }
	      catch (java.io.IOException e){}
	   }
 
	   static void enregistre(String fichier)
	   {
	      try
	      {
 
	         XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
 
 
	         sortie.output(document, new FileOutputStream(fichier));
	      }
	      catch (java.io.IOException e){}
	   }
	}
	* | 
Partager