document.addDocType( "beans", "-//SPRING//DTD BEAN//EN", //$NON-NLS-1$ //$NON-NLS-2$
"http://www.springframework.org/dtd/spring-beans.dtd" ); //$NON-NLS-1$
// Creating the output stream we're going to put the XML in
OutputStream os = new ByteArrayOutputStream();
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setEncoding( "UTF-8" ); //$NON-NLS-1$
// Writing the XML.
XMLWriter writer = new XMLWriter( os, outformat );
writer.write( document );
writer.flush();