KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > xml > XmlDemo


1 // This program is free software; you can redistribute it and/or modify
2
// it under the terms of the GNU General Public License as published by
3
// the Free Software Foundation; either version 2 of the License, or
4
// (at your option) any later version.
5
//
6
// This program is distributed in the hope that it will be useful,
7
// but WITHOUT ANY WARRANTY; without even the implied warranty of
8
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
// GNU Library General Public License for more details.
10
//
11
// You should have received a copy of the GNU General Public License
12
// along with this program; if not, write to the Free Software
13
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
package org.columba.core.xml;
15
16 import java.io.IOException JavaDoc;
17 import java.net.MalformedURLException JavaDoc;
18 import java.net.URL JavaDoc;
19
20
21 public class XmlDemo {
22     public XmlDemo() {
23     }
24
25     public static void main(String JavaDoc[] argv) {
26         if (argv.length != 1) {
27             System.err.println("Usage: cmd url");
28             System.exit(1);
29         }
30
31         XmlIO X = new XmlIO();
32
33         try {
34             X.load(new URL JavaDoc(argv[0]));
35         } catch (MalformedURLException JavaDoc mue) {
36             System.err.println("No valid url: \"" + argv[0] + "\"");
37             System.exit(1);
38         }
39
40         XmlElement.printNode(X.getRoot(), "");
41
42         System.out.println("---------------------------------------------");
43
44         XmlElement E = X.getRoot().getElement("options");
45
46         if (E != null) {
47             System.out.println("options: '" + E.getData() + "'");
48         }
49
50         E = X.getRoot().getElement("/options/gui/window/width");
51
52         if (E != null) {
53             System.out.println("options/gui/window/width: '" + E.getData() +
54                 "'");
55         } else {
56             System.out.println("options/gui/window/width: " +
57                 "**Not found in this XML document**");
58         }
59
60         System.out.println("---------------------------------------------");
61
62         try {
63             X.write(System.out);
64         } catch (IOException JavaDoc e) {
65             System.out.println("Error in write: " + e.toString());
66         }
67     }
68 }
69
Popular Tags