Outputting a Document Using XMLOutputter
import java.io.IOException; import org.jdom.Document; import org.jdom.Element; import org.jdom.output.XMLOutputter; public class MainClass { public static void main(String args[]) throws IOException { Document doc = new Document(new Element("games")); Element newGame = new Element("game").setText("Final Fantasy"); doc.getRootElement().addContent(newGame); newGame.setAttribute("genre", "rpg"); XMLOutputter domstream = new XMLOutputter(); domstream.output(doc, System.out); } }