“Java Créer XML” Réponses codées

Java Créer XML

Create a DocumentBuilder instance.
Create a Document from the above DocumentBuilder .
Create the elements you want using the Element class and its appendChild method.
Create a new Transformer instance and a new DOMSource instance.
Create a new StreamResult to the output stream you want to use
Frightened Ferret

Java Créer XML


//Root Element
Element root=new Element("CONFIGURATION");
Document doc=new Document();
//Element 1
Element child1=new Element("BROWSER");
//Element 1 Content
child1.addContent("chrome");
//Element 2
Element child2=new Element("BASE");
//Element 2 Content
child2.addContent("http:fut");
//Element 3
Element child3=new Element("EMPLOYEE");
//Element 3 --> In this case this element has another element with Content
child3.addContent(new Element("EMP_NAME").addContent("Anhorn, Irene"));

//Add it in the root Element
root.addContent(child1);
root.addContent(child2);
root.addContent(child3);
//Define root element like root
doc.setRootElement(root);
//Create the XML
XMLOutputter outter=new XMLOutputter();
outter.setFormat(Format.getPrettyFormat());
outter.output(doc, new FileWriter(new File("myxml.xml")));

Clean Chipmunk

Réponses similaires à “Java Créer XML”

Questions similaires à “Java Créer XML”

Plus de réponses similaires à “Java Créer XML” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code