Writing XML Documents with JDOM

Once you've created a document, you're likely to want to serialize it to a network socket, a file, a string, or some other stream. JDOM's org.jdom.output.XMLOutputter class does this in a standard way. You can create an XMLOutputter object with a no-args constructor and then write a document onto an OutputStream with its output() method. For example, the following code fragment writes the Document object named doc onto System.out:

XMLOutputter outputter = new XMLOutputter(); 
try {
  outputter.output(doc, System.out);
}
catch (IOException e) {
  System.err.println(e);
}

Although you also can output a document onto a java.io.Writer, it's recommended that you use an OutputStream because it's generally not possible to ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.