01: /*
02: * Copyright 2002-2008 Andy Clark
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package sample;
18:
19: import org.cyberneko.html.parsers.DOMParser;
20: import org.w3c.dom.Node;
21:
22: /**
23: * This program tests the NekoHTML parser's use of the HTML DOM
24: * implementation by printing the class names of all the nodes in
25: * the parsed document.
26: *
27: * @author Andy Clark
28: *
29: * @version $Id: TestHTMLDOM.java,v 1.3 2004/02/19 20:00:17 andyc Exp $
30: */
31: public class TestHTMLDOM {
32:
33: //
34: // MAIN
35: //
36:
37: /** Main. */
38: public static void main(String[] argv) throws Exception {
39: DOMParser parser = new DOMParser();
40: for (int i = 0; i < argv.length; i++) {
41: parser.parse(argv[i]);
42: print(parser.getDocument(), "");
43: }
44: } // main(String[])
45:
46: //
47: // Public static methods
48: //
49:
50: /** Prints a node's class name. */
51: public static void print(Node node, String indent) {
52: System.out.println(indent + node.getClass().getName());
53: Node child = node.getFirstChild();
54: while (child != null) {
55: print(child, indent + " ");
56: child = child.getNextSibling();
57: }
58: } // print(Node)
59:
60: } // class TestHTMLDOM
|