JDOM provides a convenient interface for dynamic XML-document creation. Here we require no implementation-drivers (like in SAX or DOM); and we manage explicit Java classes rather than interfaces.

In order to create new XML-contents with JDOM we just have to define its root element before and then instantiate a document for it. It is shown in sample below:

 import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;

 * This sample program showing how to create new JDOM document.

public class Test {
    public static void main(String[] args) {
        try {

            // first we have to create a document element:
            Element order = new Element("purchase-order");
            // ... the we can define a document:
            Document document = new Document(order);
            // we can event compose and insert our document type:
            DocType type = new DocType("purchase-order");
            // .. create some other contents ...
        } catch (Exception ex) {