1 9 10 package org.dom4j.samples.dom; 11 12 import org.dom4j.samples.AbstractDemo; 13 14 import javax.xml.parsers.DocumentBuilder ; 15 import javax.xml.parsers.DocumentBuilderFactory ; 16 17 import org.dom4j.Document; 18 import org.dom4j.io.DOMReader; 19 20 27 public class DOMDemo extends AbstractDemo { 28 29 public static void main(String [] args) { 30 run(new DOMDemo(), args); 31 } 32 33 public DOMDemo() { 34 } 35 36 protected Document parse(String url) throws Exception { 37 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 39 DocumentBuilder builder = factory.newDocumentBuilder(); 40 41 println("Loading document with JAXP builder: " + builder); 42 43 org.w3c.dom.Document domDocument = builder.parse(url); 44 45 println("Created W3C DOM document: " + domDocument); 46 47 DOMReader reader = new DOMReader(); 49 Document document = reader.read(domDocument); 50 51 println("Created DOM4J document: " + document); 52 53 return document; 54 } 55 56 protected void process(Document document) throws Exception { 57 writer.write(document); 58 } 59 } 60 61 99 | Popular Tags |