| 12
 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
 
 |  
 import java.io.FileOutputStream;  
 import java.io.OutputStream;  
 import javax.swing.JOptionPane;  
 import org.jdom.*;  
 import org.jdom.output.Format;  
 import org.jdom.output.XMLOutputter;  
 
public class CreerXML {  
 
   public static Element root = new Element("customer");  
     public static Document document = new Document(root);  
 
    public static void main(String args[]){  
     Element code= new Element("code");  
     root.addContent(code);  
     Element name= new Element("name");  
     root.addContent(name);  
     Element city = new Element("city");  
     root.addContent(city);  
 
     save("test.xml");  
     }  
 
     public static void save(String file){  
 
       try {  
            XMLOutputter out= new XMLOutputter(Format.getPrettyFormat());  
             out.output(document, new FileOutputStream(file));  
 
         } catch (Exception e) {  
             JOptionPane.showMessageDialog(null, e.getMessage());  
         }  
     } | 
Partager