There are several ways and formats for the JDOM document to be save in. In order to write an XML file from a documetn we have to use class XMLOutputter. It allows to save the document either to a file or to a String object in memory. Besides entire document we can save separate JDOM elements. XML and String outputs are shown in the sample below:

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

 * This sample program showing how to create new
 * JDOM document and save it to a file.

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 ...
            // save it to a file:
            XMLOutputter out = new XMLOutputter();
   writer = new"order.xml");
            out.output(document, writer);
            // ... or save it to a string and print:
        } catch (Exception ex) {