1 7 8 package sample; 9 10 import org.cyberneko.html.parsers.DOMFragmentParser; 11 import org.apache.html.dom.HTMLDocumentImpl; 12 import org.w3c.dom.Document ; 13 import org.w3c.dom.DocumentFragment ; 14 import org.w3c.dom.Node ; 15 import org.w3c.dom.html.HTMLDocument; 16 17 26 public class TestHTMLDOMFragment { 27 28 32 33 public static void main(String [] argv) throws Exception { 34 DOMFragmentParser parser = new DOMFragmentParser(); 35 HTMLDocument document = new HTMLDocumentImpl(); 36 for (int i = 0; i < argv.length; i++) { 37 DocumentFragment fragment = document.createDocumentFragment(); 38 parser.parse(argv[i], fragment); 39 print(fragment, ""); 40 } 41 } 43 47 48 public static void print(Node node, String indent) { 49 System.out.println(indent+node.getClass().getName()); 50 Node child = node.getFirstChild(); 51 while (child != null) { 52 print(child, indent+" "); 53 child = child.getNextSibling(); 54 } 55 } 57 } | Popular Tags |