KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > TestHTMLDOMFragment


1 /*
2  * (C) Copyright 2002-2004, Andy Clark. All rights reserved.
3  *
4  * This file is distributed under an Apache style license. Please
5  * refer to the LICENSE file for specific details.
6  */

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 JavaDoc;
13 import org.w3c.dom.DocumentFragment JavaDoc;
14 import org.w3c.dom.Node JavaDoc;
15 import org.w3c.dom.html.HTMLDocument;
16
17 /**
18  * This program tests the NekoHTML parser's use of the HTML DOM
19  * implementation to parse document fragments by printing the
20  * class names of all the nodes in the parsed document.
21  *
22  * @author Andy Clark
23  *
24  * @version $Id: TestHTMLDOMFragment.java,v 1.3 2004/02/19 20:00:17 andyc Exp $
25  */

26 public class TestHTMLDOMFragment {
27
28     //
29
// MAIN
30
//
31

32     /** Main. */
33     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
34         DOMFragmentParser parser = new DOMFragmentParser();
35         HTMLDocument document = new HTMLDocumentImpl();
36         for (int i = 0; i < argv.length; i++) {
37             DocumentFragment JavaDoc fragment = document.createDocumentFragment();
38             parser.parse(argv[i], fragment);
39             print(fragment, "");
40         }
41     } // main(String[])
42

43     //
44
// Public static methods
45
//
46

47     /** Prints a node's class name. */
48     public static void print(Node JavaDoc node, String JavaDoc indent) {
49         System.out.println(indent+node.getClass().getName());
50         Node JavaDoc child = node.getFirstChild();
51         while (child != null) {
52             print(child, indent+" ");
53             child = child.getNextSibling();
54         }
55     } // print(Node)
56

57 } // class TestHTMLDOMFragment
Popular Tags