1 9 10 package org.dom4j.samples; 11 12 import java.io.StringReader ; 13 import java.io.StringWriter ; 14 15 import org.dom4j.Document; 16 import org.dom4j.io.SAXReader; 17 import org.dom4j.io.XMLWriter; 18 19 26 public class RoundTripDemo extends SAXDemo { 27 28 public static void main(String [] args) { 29 run(new RoundTripDemo(), args); 30 } 31 32 public RoundTripDemo() { 33 } 34 35 36 protected void process(Document document) throws Exception { 37 38 System.out.println("about to output: " + document); 39 40 StringWriter out = new StringWriter (); 42 XMLWriter writer = new XMLWriter(out); 43 writer.write(document); 44 writer.close(); 45 46 StringReader in = new StringReader (out.toString()); 48 SAXReader reader = new SAXReader(); 49 Document doc2 = reader.read(in); 50 51 System.out.println("parsed back again: " + doc2); 52 53 writer.setOutputStream(System.out); 55 writer.write(doc2); 56 } 57 } 58 59 97 | Popular Tags |