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
|
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
public class JDOM2 {
static Element racine = new Element("livres");
static Document document = new Document(racine);
@SuppressWarnings("unused")
private static Element dateParution;
public static void main(String[] args) throws IOException {
Element livre = new Element("livre");
racine.addContent(livre);
Attribute id = new Attribute("id","1");
livre.setAttribute(id);
Element titre = new Element("titre");
livre.addContent(titre);
titre.setText("titre");
Element auteur = new Element("auteur");
livre.addContent(auteur);
auteur.setText("auteur");
Element type = new Element("type");
livre.addContent(type);
type.setText("type");
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
sortie.output(document, System.out);
// sortie.output(document, new
// FileOutputStream("C:/workspace/JDOM_arboressence/ressources/livres.xml"));
}
} |