1 package org.columba.core.xml; 15 16 import java.io.IOException ; 17 import java.net.MalformedURLException ; 18 import java.net.URL ; 19 20 21 public class XmlDemo { 22 public XmlDemo() { 23 } 24 25 public static void main(String [] 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 (argv[0])); 35 } catch (MalformedURLException 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 e) { 65 System.out.println("Error in write: " + e.toString()); 66 } 67 } 68 } 69 | Popular Tags |