KickJava   Java API By Example, From Geeks To Geeks.

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


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: DOMDemo.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 javax.xml.parsers.DocumentBuilder JavaDoc;
15 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
16
17 import org.dom4j.Document;
18 import org.dom4j.io.DOMReader;
19
20 /**
21  * A simple test program to demonstrate using W3C DOM and JAXP to load a DOM XML
22  * tree then converting it to a DOM4J tree.
23  *
24  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
25  * @version $Revision: 1.4 $
26  */

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

99
Popular Tags