KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > samples > dom > NativeDOMDemo


1 /*
2  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  *
7  * $Id: NativeDOMDemo.java,v 1.4 2005/01/29 14:52:58 maartenc Exp $
8  */

9
10 package org.dom4j.samples.dom;
11
12 import org.dom4j.samples.AbstractDemo;
13
14 import org.dom4j.Document;
15 import org.dom4j.dom.DOMDocumentFactory;
16 import org.dom4j.io.SAXReader;
17
18 /**
19  * A simple test program to demonstrate the use of native DOM support.
20  *
21  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
22  * @version $Revision: 1.4 $
23  */

24 public class NativeDOMDemo extends AbstractDemo {
25
26     public static void main(String JavaDoc[] args) {
27         run(new NativeDOMDemo(), args);
28     }
29
30     public NativeDOMDemo() {
31     }
32
33     public void run(String JavaDoc[] args) throws Exception JavaDoc {
34         if (args.length < 1) {
35             printUsage("<XML document URL>");
36             return;
37         }
38
39         parseDOM(args[0]);
40     }
41
42     protected void parseDOM(String JavaDoc xmlFile) throws Exception JavaDoc {
43
44         println("Loading document: " + xmlFile);
45
46         SAXReader reader = new SAXReader(DOMDocumentFactory.getInstance());
47         Document document = reader.read(xmlFile);
48
49         println("Created <dom4j> document: " + document);
50
51         if (document instanceof org.w3c.dom.Document JavaDoc) {
52             org.w3c.dom.Document JavaDoc domDocument = (org.w3c.dom.Document JavaDoc) document;
53             println("Created W3C DOM document: " + domDocument);
54             processDOM(domDocument);
55         } else {
56             println("FAILED to make a native W3C DOM document!!");
57         }
58     }
59
60     protected void processDOM(org.w3c.dom.Document JavaDoc document) throws Exception JavaDoc {
61     }
62 }
63
64 /*
65  * Redistribution and use of this software and associated documentation
66  * ("Software"), with or without modification, are permitted provided that the
67  * following conditions are met:
68  *
69  * 1. Redistributions of source code must retain copyright statements and
70  * notices. Redistributions must also contain a copy of this document.
71  *
72  * 2. Redistributions in binary form must reproduce the above copyright notice,
73  * this list of conditions and the following disclaimer in the documentation
74  * and/or other materials provided with the distribution.
75  *
76  * 3. The name "DOM4J" must not be used to endorse or promote products derived
77  * from this Software without prior written permission of MetaStuff, Ltd. For
78  * written permission, please contact dom4j-info@metastuff.com.
79  *
80  * 4. Products derived from this Software may not be called "DOM4J" nor may
81  * "DOM4J" appear in their names without prior written permission of MetaStuff,
82  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
83  *
84  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
85  *
86  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
87  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
90  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
91  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
92  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
93  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
94  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
95  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
96  * POSSIBILITY OF SUCH DAMAGE.
97  *
98  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
99  *
100  * $Id: NativeDOMDemo.java,v 1.4 2005/01/29 14:52:58 maartenc Exp $
101  */

102
Popular Tags