1 9 10 package org.dom4j.samples.jaxp; 11 12 import org.dom4j.samples.SAXDemo; 13 14 import java.io.StringWriter ; 15 16 import javax.xml.transform.Source ; 17 import javax.xml.transform.Transformer ; 18 import javax.xml.transform.TransformerFactory ; 19 import javax.xml.transform.stream.StreamResult ; 20 21 import org.dom4j.Document; 22 import org.dom4j.io.DocumentSource; 23 24 30 public class WriterDemo extends SAXDemo { 31 32 public static void main(String [] args) { 33 run(new WriterDemo(), args); 34 } 35 36 public WriterDemo() { 37 } 38 39 40 protected void process(Document document) throws Exception { 41 TransformerFactory factory = TransformerFactory.newInstance(); 43 Transformer transformer = factory.newTransformer(); 44 45 Source source = new DocumentSource(document); 48 StringWriter buffer = new StringWriter (); 49 StreamResult result = new StreamResult (buffer); 50 transformer.transform(source, result); 51 52 String text = buffer.toString(); 53 System.out.println("The document is:- "); 54 System.out.println(text); 55 } 56 } 57 58 96 | Popular Tags |