KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > TestHTMLDOM


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

23 public class TestHTMLDOM {
24
25     //
26
// MAIN
27
//
28

29     /** Main. */
30     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
31         DOMParser parser = new DOMParser();
32         for (int i = 0; i < argv.length; i++) {
33             parser.parse(argv[i]);
34             print(parser.getDocument(), "");
35         }
36     } // main(String[])
37

38     //
39
// Public static methods
40
//
41

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

52 } // class TestHTMLDOM
53
Popular Tags