01: // This program is free software; you can redistribute it and/or modify
02: // it under the terms of the GNU General Public License as published by
03: // the Free Software Foundation; either version 2 of the License, or
04: // (at your option) any later version.
05: //
06: // This program is distributed in the hope that it will be useful,
07: // but WITHOUT ANY WARRANTY; without even the implied warranty of
08: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
09: // 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;
17: import java.net.MalformedURLException;
18: import java.net.URL;
19:
20: public class XmlDemo {
21: public XmlDemo() {
22: }
23:
24: public static void main(String[] argv) {
25: if (argv.length != 1) {
26: System.err.println("Usage: cmd url");
27: System.exit(1);
28: }
29:
30: XmlIO X = new XmlIO();
31:
32: try {
33: X.load(new URL(argv[0]));
34: } catch (MalformedURLException mue) {
35: System.err.println("No valid url: \"" + argv[0] + "\"");
36: System.exit(1);
37: }
38:
39: XmlElement.printNode(X.getRoot(), "");
40:
41: System.out
42: .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: '"
54: + E.getData() + "'");
55: } else {
56: System.out.println("options/gui/window/width: "
57: + "**Not found in this XML document**");
58: }
59:
60: System.out
61: .println("---------------------------------------------");
62:
63: try {
64: X.write(System.out);
65: } catch (IOException e) {
66: System.out.println("Error in write: " + e.toString());
67: }
68: }
69: }
|