1 9 10 package org.dom4j.samples.dom; 11 12 import org.dom4j.samples.SAXDemo; 13 14 import org.dom4j.Document; 15 import org.dom4j.io.DOMReader; 16 import org.dom4j.io.DOMWriter; 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 DOMWriter writer = new DOMWriter(); 42 org.w3c.dom.Document domDocument = writer.write(document); 43 44 DOMReader reader = new DOMReader(); 46 Document doc2 = reader.read(domDocument); 47 48 System.out.println("parsed back again: " + doc2); 49 50 XMLWriter xmlWriter = new XMLWriter(System.out); 52 xmlWriter.write(doc2); 53 } 54 } 55 56 94 | Popular Tags |