1 9 10 package org.dom4j.samples.dom; 11 12 import org.dom4j.samples.XSLTDemo; 13 14 import javax.xml.transform.Source ; 15 import javax.xml.transform.Transformer ; 16 import javax.xml.transform.TransformerFactory ; 17 import javax.xml.transform.dom.DOMSource ; 18 import javax.xml.transform.stream.StreamResult ; 19 import javax.xml.transform.stream.StreamSource ; 20 21 import org.dom4j.Document; 22 import org.dom4j.dom.DOMDocumentFactory; 23 import org.dom4j.io.DOMWriter; 24 import org.dom4j.io.SAXReader; 25 26 32 public class XSLTNativeDOMDemo extends XSLTDemo { 33 34 public static void main(String [] args) { 35 run(new XSLTNativeDOMDemo(), args); 36 } 37 38 public XSLTNativeDOMDemo() { 39 } 40 41 protected Document parse(String url) throws Exception { 42 SAXReader reader = new SAXReader(DOMDocumentFactory.getInstance()); 43 return reader.read(url); 44 } 45 46 47 protected void process(Document document) throws Exception { 48 TransformerFactory factory = TransformerFactory.newInstance(); 50 Transformer transformer = factory.newTransformer(new StreamSource (xsl 51 .toString())); 52 53 DOMWriter domWriter = new DOMWriter(); 56 57 long start = System.currentTimeMillis(); 58 org.w3c.dom.Document domDocument = domWriter.write(document); 59 long end = System.currentTimeMillis(); 60 61 System.out.println("Converting to a W3C Document took: " 62 + (end - start) + " milliseconds"); 63 64 Source source = new DOMSource (domDocument); 67 StreamResult result = new StreamResult (System.out); 68 transformer.transform(source, result); 69 } 70 71 } 72 73 111 | Popular Tags |