1 9 10 package org.dom4j.samples; 11 12 import java.io.BufferedInputStream ; 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.InputStream ; 16 import java.net.URL ; 17 18 import org.dom4j.Document; 19 import org.dom4j.io.DOMReader; 20 import org.w3c.tidy.Tidy; 21 22 29 public class JTidyDemo extends AbstractDemo { 30 31 public static void main(String [] args) { 32 run(new JTidyDemo(), args); 33 } 34 35 public JTidyDemo() { 36 } 37 38 protected Document parse(String xmlFile) throws Exception { 39 InputStream in = openStream(xmlFile); 40 Tidy tidy = new Tidy(); 41 tidy.setXmlOut(true); 42 org.w3c.dom.Document domDocument = tidy.parseDOM(in, null); 43 44 DOMReader domReader = new DOMReader(); 45 return domReader.read(domDocument); 46 } 47 48 protected InputStream openStream(String xmlFile) throws Exception { 49 File file = new File (xmlFile); 50 if (file.exists()) { 51 return new BufferedInputStream (new FileInputStream (file)); 52 } 53 return new URL (xmlFile).openStream(); 54 } 55 56 } 57 58 96 | Popular Tags |