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.apache.html.dom.HTMLDocumentImpl;
20: import org.cyberneko.html.parsers.DOMFragmentParser;
21: import org.w3c.dom.DocumentFragment;
22: import org.w3c.dom.Node;
23: import org.w3c.dom.html.HTMLDocument;
24:
25: /**
26: * This program tests the NekoHTML parser's use of the HTML DOM
27: * implementation to parse document fragments by printing the
28: * class names of all the nodes in the parsed document.
29: *
30: * @author Andy Clark
31: *
32: * @version $Id: TestHTMLDOMFragment.java,v 1.3 2004/02/19 20:00:17 andyc Exp $
33: */
34: public class TestHTMLDOMFragment {
35:
36: //
37: // MAIN
38: //
39:
40: /** Main. */
41: public static void main(String[] argv) throws Exception {
42: DOMFragmentParser parser = new DOMFragmentParser();
43: HTMLDocument document = new HTMLDocumentImpl();
44: for (int i = 0; i < argv.length; i++) {
45: DocumentFragment fragment = document
46: .createDocumentFragment();
47: parser.parse(argv[i], fragment);
48: print(fragment, "");
49: }
50: } // main(String[])
51:
52: //
53: // Public static methods
54: //
55:
56: /** Prints a node's class name. */
57: public static void print(Node node, String indent) {
58: System.out.println(indent + node.getClass().getName());
59: Node child = node.getFirstChild();
60: while (child != null) {
61: print(child, indent + " ");
62: child = child.getNextSibling();
63: }
64: } // print(Node)
65:
66: } // class TestHTMLDOMFragment
|