List of usage examples for org.dom4j.io XMLResult XMLResult
public XMLResult(OutputStream out, OutputFormat format) throws UnsupportedEncodingException
From source file:org.dom4j.samples.jaxp.PrettyPrintDemo.java
License:Open Source License
/** Outputs the document using JAXP */ protected void process(Document document) throws Exception { // load a default transformer TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); // use dom4j document as the source Source source = new DocumentSource(document); // use pretty print format and a buffer for the result OutputFormat format = OutputFormat.createPrettyPrint(); StringWriter buffer = new StringWriter(); Result result = new XMLResult(buffer, format); // now lets transform transformer.transform(source, result); String text = buffer.toString(); System.out.println("The document is:- "); System.out.println(text);//from w ww. ja v a 2 s.c o m }