1 9 10 package org.dom4j.samples.dom; 11 12 import org.dom4j.samples.AbstractDemo; 13 14 import org.dom4j.Document; 15 import org.dom4j.dom.DOMDocumentFactory; 16 import org.dom4j.io.SAXReader; 17 18 24 public class NativeDOMDemo extends AbstractDemo { 25 26 public static void main(String [] args) { 27 run(new NativeDOMDemo(), args); 28 } 29 30 public NativeDOMDemo() { 31 } 32 33 public void run(String [] args) throws Exception { 34 if (args.length < 1) { 35 printUsage("<XML document URL>"); 36 return; 37 } 38 39 parseDOM(args[0]); 40 } 41 42 protected void parseDOM(String xmlFile) throws Exception { 43 44 println("Loading document: " + xmlFile); 45 46 SAXReader reader = new SAXReader(DOMDocumentFactory.getInstance()); 47 Document document = reader.read(xmlFile); 48 49 println("Created <dom4j> document: " + document); 50 51 if (document instanceof org.w3c.dom.Document ) { 52 org.w3c.dom.Document domDocument = (org.w3c.dom.Document ) document; 53 println("Created W3C DOM document: " + domDocument); 54 processDOM(domDocument); 55 } else { 56 println("FAILED to make a native W3C DOM document!!"); 57 } 58 } 59 60 protected void processDOM(org.w3c.dom.Document document) throws Exception { 61 } 62 } 63 64 102 | Popular Tags |