1 package org.enhydra.xml; 2 3 import java.util.Properties ; 4 5 import org.w3c.dom.Document ; 6 import org.w3c.dom.Node ; 7 8 15 public class XMLConfig extends SearchElement { 16 17 18 21 public XMLConfig() { 22 } 23 24 25 32 public XMLConfig(Document ownerDoc, String name) { 33 super(ownerDoc, name); 34 } 35 36 37 43 public XMLConfig(Node node) { 44 super(node); 45 } 46 47 48 54 public XMLConfig(XMLConfig node) { 55 super((HashMapElement)node); 56 } 57 58 59 66 protected Node newElementInstance(Node node) { 67 return new XMLConfig(node); 68 } 69 70 71 79 public static XMLConfig newXMLConfigInstance(Document document) { 80 Node root = document.getDocumentElement(); 81 return new XMLConfig(root); 82 } 83 84 85 90 public XMLConfig getSection(String name) { 91 return (XMLConfig)getFirstSubElementsByCondition(name); 92 } 93 94 95 143 144 145 public static void main(String [] args) { 146 try { 147 System.out.println("Reading document ..."); 148 Document doc = XMLDocumentFactory.parse("input.xml"); 149 System.out.println("Creating node ..."); 150 XMLConfig node = XMLConfig.newXMLConfigInstance(doc); 151 System.out.println("Serialize node ..."); 152 153 Properties prop = new Properties (); 154 prop.put(javax.xml.transform.OutputKeys.DOCTYPE_PUBLIC,"http:///enhydra.org"); 155 prop.put(javax.xml.transform.OutputKeys.VERSION,"1.1"); 156 XMLDocumentFactory.serialize(node, "output.xml ",prop); 157 System.out.println("Searching ..."); 158 159 for (int i=0; i < 1000; i++) { 160 if ( i%10 == 0) 161 System.out.print("\rprogress "+i/10+" %"); 162 XMLConfig section = node.getSection("database/package/package/package/package/package/package/table/column@id=EMAILADRESSE"); 163 } 165 System.out.println("\rprogress 100 %"); 166 System.out.println(); 167 168 XMLConfig section = node.getSection("database/package/package/package/package/package/package/table/column@id=EMAILADRESSE"); 170 section.setAttr("type@javaType","Zoka"); 171 if (section == null) 172 System.out.println("section = null"); 173 else { 174 System.out.println("section = "+section); 175 } 176 177 178 187 } catch(Exception e) { 188 e.printStackTrace(); 189 System.out.println("NOOOOOOOOOOOOO"); 190 } 191 } 192 } 193 | Popular Tags |