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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package application_uml;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import java.io.FileOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
/**
*
* @author Nahla
*/
public class WriteXML {
// constructeur
public WriteXML(){
try {
this.writeXMLelement();
}
catch(ParserConfigurationException paser){
}
catch(FileNotFoundException filenotFound){
}
catch(IOException IoEx){
}
}
// methode contenue de XML
public void writeXMLelement () throws ParserConfigurationException , FileNotFoundException , IOException {
// creer DocumentBuilderFactory
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
// crer DocumentBuilder
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
//creer Document
Document XmlFile = docBuilder.newDocument();
// build XML element and texts
// on va assimler un modele
Element rootElement = XmlFile.createElement("Diagramme");
Element mainElement = XmlFile.createElement("classe"); // meme pour att , leth , ass , relation , ...
Text classeNameText = XmlFile.createTextNode("ma classe"); // entre balise
Element AccessClass = XmlFile.createElement("Access Control");
Element ContainerClass = XmlFile.createElement("Container");
Element ContainerClassValue = XmlFile.createElement("Value Container ");
AccessClass.appendChild(classeNameText);
ContainerClass.appendChild(classeNameText);
ContainerClassValue.appendChild(classeNameText);
mainElement.appendChild(classeNameText);
rootElement.appendChild(mainElement);
XmlFile.appendChild(rootElement);
// set OutputFormat
OutputFormat outFormat = new OutputFormat(XmlFile);
outFormat.setIndenting(true);
//Declarer le fichier
File sortieXml = new File("sortieXML.xml");
// declarer fichier sortie FileOutputStream
FileOutputStream outStream = new FileOutputStream ( sortieXml);
// XML serializer pour serializer XML Data
XMLSerializer serialzer = new XMLSerializer (outStream, outFormat);
serialzer.serialize(XmlFile);
}
public static void main ( String [] args ){
// instancier
WriteXML writexml = new WriteXML();
}
} |
Partager