KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > xml > XmlUtil


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: XSLTUtil.java,v 1.32.6.1.2.1 2002/12/11
22  */

23
24 /*
25  *
26  * @author Nenad Vico
27  * @version $Revision: 1.1 $
28  *
29  */

30 package org.enhydra.dods.xml;
31
32 import java.io.File JavaDoc;
33 import java.io.FileOutputStream JavaDoc;
34 import java.io.OutputStream JavaDoc;
35 import java.util.Properties JavaDoc;
36 import javax.xml.parsers.DocumentBuilder JavaDoc;
37 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
38 import javax.xml.transform.Transformer JavaDoc;
39 import javax.xml.transform.TransformerFactory JavaDoc;
40 import javax.xml.transform.dom.DOMSource JavaDoc;
41 import javax.xml.transform.stream.StreamResult JavaDoc;
42 import org.apache.xalan.processor.TransformerFactoryImpl;
43 import org.w3c.dom.Document JavaDoc;
44 import org.w3c.dom.Element JavaDoc;
45 import org.w3c.dom.NodeList JavaDoc;
46
47 public class XmlUtil {
48     
49     protected String JavaDoc xmlFile;
50     protected Document JavaDoc document;
51     public XmlUtil(String JavaDoc xmlFile) throws XmlUtilException {
52         this.xmlFile = xmlFile;
53         try { // read DOM parser
54
DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
55             DocumentBuilder JavaDoc db = dbf.newDocumentBuilder();
56
57             document = db.parse(xmlFile);
58         } catch (Exception JavaDoc e) {
59             e.printStackTrace();
60         }
61     }
62
63     /**
64      * Store DOM source in xml file.
65      */

66     public void store() throws XmlUtilException {
67         store(null);
68     }
69
70     /**
71      * Store DOM source in xml file.
72      *
73      * @param properties Output properties for xml file.
74      */

75     public void store(Properties JavaDoc properties) throws XmlUtilException {
76         store(null, properties);
77     }
78
79     /**
80      * Store DOM source in xml file.
81      *
82      * @param properties Output properties for xml file.
83      * @param fileName Output xml file name.
84      */

85     public void store(String JavaDoc fileName, Properties JavaDoc properties) throws XmlUtilException {
86         TransformerFactory JavaDoc tf = null;
87         DOMSource JavaDoc src = null;
88
89         if (fileName == null) {
90             fileName = xmlFile;
91         }
92         tf = TransformerFactoryImpl.newInstance();
93         src = new DOMSource JavaDoc(document.getDocumentElement());
94         if (tf == null) {
95             return;
96         }
97         if (src == null) {
98             return;
99         }
100         OutputStream JavaDoc outputs = null;
101
102         try {
103             File JavaDoc f = new File JavaDoc(fileName);
104             File JavaDoc pf = f.getParentFile();
105
106             if (pf != null) {
107                 pf.mkdirs();
108             }
109             outputs = new FileOutputStream JavaDoc(f.getPath());
110             Transformer JavaDoc serializer = tf.newTransformer();
111
112             if (properties != null) {
113                 serializer.setOutputProperties(properties);
114             }
115             serializer.transform(src, new StreamResult JavaDoc(outputs));
116         } catch (java.io.FileNotFoundException JavaDoc e) {
117             throw new XmlUtilException(e);
118         } catch (javax.xml.transform.TransformerConfigurationException JavaDoc e) {
119             throw new XmlUtilException(e);
120         } catch (javax.xml.transform.TransformerException JavaDoc e) {
121             throw new XmlUtilException(e);
122         }
123     }
124
125     /**
126      * Return value of single text node defined by key parameter.
127      *
128      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
129      * (e.g. /doml/database).
130      *
131      * @return Value of single text node defined by key parameter or null if tag doesn't exist.
132      */

133     public String JavaDoc getSingleTextNode(String JavaDoc key) throws XmlUtilException {
134         return getSingleTextNode(key, null);
135     }
136
137     /**
138      * Return value of single text node defined by key parameter.
139      *
140      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
141      * (e.g. /doml/database).
142      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
143      * (starting from level 0). These numbers tell to which appearance of specific
144      * tag key tag belongs to. It is not necessary to provide all tag levels.
145      *
146      * @return Value of single text node defined by key parameter or null if tag doesn't exist.
147      */

148     public String JavaDoc getSingleTextNode(String JavaDoc key, int levelNodes[]) throws XmlUtilException {
149         String JavaDoc nodeValue = "";
150         NodeList JavaDoc tagElems;
151         Element JavaDoc tagElem;
152         String JavaDoc tag;
153         String JavaDoc subKey;
154         int cuurentLevel = 0;
155         int pos = key.indexOf("/");
156
157         if (pos < 0) {
158             return null;
159         }
160         if (pos == 0) { // cut leading separator "/"
161
subKey = key.substring(pos + 1);
162             pos = subKey.indexOf("/");
163         } else {
164             subKey = key;
165         }
166         try {
167             if (pos != -1) {
168                 tag = subKey.substring(0, pos);
169                 subKey = subKey.substring(pos + 1);
170                 tagElems = document.getElementsByTagName(tag);
171                 tagElem = (Element JavaDoc) tagElems.item(0);
172                 cuurentLevel++;
173                 pos = subKey.indexOf("/");
174                 if (pos != -1) {
175                     while (pos != -1) {
176                         tag = subKey.substring(0, pos);
177                         subKey = subKey.substring(pos + 1);
178                         tagElems = tagElem.getElementsByTagName(tag);
179                         if (levelNodes != null
180                                 && cuurentLevel < levelNodes.length) {
181                             tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
182                         } else {
183                             tagElem = (Element JavaDoc) tagElems.item(0);
184                         }
185                         if (tagElem == null) {
186                             return null;
187                         }
188                         cuurentLevel++;
189                         pos = subKey.indexOf("/");
190                     }
191                 }
192                 tagElems = tagElem.getElementsByTagName(subKey);
193                 if (levelNodes != null && cuurentLevel < levelNodes.length) {
194                     tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
195                 } else {
196                     tagElem = (Element JavaDoc) tagElems.item(0);
197                 }
198                 tagElems = tagElem.getChildNodes();
199                 String JavaDoc text = "";
200
201                 for (int i = 0; i < tagElems.getLength(); i++) {
202                     if (tagElems.item(i).getNodeType() == 3) { // read only text values
203
text += tagElems.item(i).getNodeValue();
204                     }
205                 }
206                 return text;
207             } else {
208                 tagElems = document.getElementsByTagName(subKey);
209                 if (levelNodes != null && cuurentLevel < levelNodes.length) {
210                     tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
211                 } else {
212                     tagElem = (Element JavaDoc) tagElems.item(0);
213                 }
214                 tagElems = tagElem.getChildNodes();
215                 String JavaDoc text = "";
216
217                 for (int i = 0; i < tagElems.getLength(); i++) {
218                     if (tagElems.item(i).getNodeType() == 3) { // read only text values
219
text += tagElems.item(i).getNodeValue();
220                     }
221                 }
222                 return text;
223             }
224         } catch (NullPointerException JavaDoc ex) {
225             throw new XmlUtilException(ex);
226         }
227     }
228
229     /**
230      * Return value of single text node defined by key parameter.
231      *
232      * @param key Full name of tag attribute which is about to be read. The tags in the key
233      * are separated by "/". Name of the attribute is separated by "@" from tag name
234      * (e.g. /doml/database@templateset).
235      *
236      * @return Value of node attribute defined by key parameter or null if attribute doesn't exist.
237      */

238     public String JavaDoc getSingleAttribute(String JavaDoc key) throws XmlUtilException {
239         return getSingleAttribute(key, null);
240     }
241
242     /**
243      * Return value of attribute node defined by key parameter.
244      *
245      * @param key Full name of tag attribute which is about to be read. The tags in the key
246      * are separated by "/". Name of the attribute is separated by "@" from tag name
247      * (e.g. /doml/database@templateset).
248      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
249      * (starting from level 0). These numbers tell to which appearance of specific
250      * tag key tag belongs to. It is not necessary to provide all tag levels.
251      *
252      * @return Value of node attribute defined by key parameter or null if attribute doesn't exist.
253      */

254     public String JavaDoc getSingleAttribute(String JavaDoc key, int levelNodes[]) throws XmlUtilException {
255         String JavaDoc nodeValue = "";
256         NodeList JavaDoc tagElems = null;
257         Element JavaDoc tagElem = null;
258         String JavaDoc tag;
259         String JavaDoc subKey;
260         String JavaDoc attrValue = null;
261         int cuurentLevel = 0;
262     
263         int pos = key.indexOf("/");
264
265         if (pos < 0) {
266             return null;
267         }
268         try {
269             if (pos == 0) { // cut leading separator "/"
270
subKey = key.substring(pos + 1);
271                 pos = subKey.indexOf("/");
272             } else {
273                 subKey = key;
274             }
275             if (pos != -1) {
276                 tag = subKey.substring(0, pos);
277                 subKey = subKey.substring(pos + 1);
278                 tagElems = document.getElementsByTagName(tag);
279                 tagElem = (Element JavaDoc) tagElems.item(0);
280                 cuurentLevel++;
281                 pos = subKey.indexOf("/");
282                 if (pos != -1) {
283                     while (pos != -1) {
284                         tag = subKey.substring(0, pos);
285                         subKey = subKey.substring(pos + 1);
286                         tagElems = tagElem.getElementsByTagName(tag);
287                         if (levelNodes != null
288                                 && cuurentLevel < levelNodes.length) {
289                             tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
290                         } else {
291                             tagElem = (Element JavaDoc) tagElems.item(0);
292                         }
293                         if (tagElem == null) {
294                             return null;
295                         }
296                         cuurentLevel++;
297                         pos = subKey.indexOf("/");
298                     }
299                 }
300                 pos = subKey.indexOf("@");
301                 tag = subKey.substring(0, pos);
302                 if (pos != -1) {
303                     tagElems = tagElem.getElementsByTagName(tag);
304                     if (levelNodes != null && cuurentLevel < levelNodes.length) {
305                         tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
306                     } else {
307                         tagElem = (Element JavaDoc) tagElems.item(0);
308                     }
309                     String JavaDoc attrName = subKey.substring(pos + 1);
310
311                     attrValue = tagElem.getAttribute(attrName);
312                 }
313             } else {
314                 pos = subKey.indexOf("@");
315                 tag = subKey.substring(0, pos);
316                 if (pos != -1) {
317                     tagElems = document.getElementsByTagName(tag);
318                     if (levelNodes != null && cuurentLevel < levelNodes.length) {
319                         tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
320                     } else {
321                         tagElem = (Element JavaDoc) tagElems.item(0);
322                     }
323                     String JavaDoc attrName = subKey.substring(pos + 1);
324
325                     attrValue = tagElem.getAttribute(attrName);
326                 }
327             }
328         } catch (NullPointerException JavaDoc ex) {
329             throw new XmlUtilException(ex);
330         }
331         if (attrValue.equals("")) {
332             attrValue = null;
333         }
334         return attrValue;
335     }
336
337     /**
338      * Set value of attribute node defined by key parameter.
339      *
340      * @param key Full name of tag attribute which is about to be read. The tags in the key
341      * are separated by "/". Name of the attribute is separated by "@" from tag name
342      * (e.g. /doml/database@templateset).
343      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
344      * (starting from level 0). These numbers tell to which appearance of specific
345      * tag key tag belongs to. It is not necessary to provide all tag levels.
346      * @param value New value of attribute node.
347      *
348      */

349     public void setSingleAttribute(String JavaDoc key, int levelNodes[], String JavaDoc value) throws XmlUtilException {
350         String JavaDoc nodeValue = "";
351         NodeList JavaDoc tagElems = null;
352         Element JavaDoc tagElem = null;
353         String JavaDoc tag;
354         String JavaDoc subKey;
355         int cuurentLevel = 0;
356     
357         int pos = key.indexOf("/");
358
359         if (pos < 0) {
360             return;
361         }
362         try {
363             if (pos == 0) { // cut leading separator "/"
364
subKey = key.substring(pos + 1);
365                 pos = subKey.indexOf("/");
366             } else {
367                 subKey = key;
368             }
369             if (pos != -1) {
370                 tag = subKey.substring(0, pos);
371                 subKey = subKey.substring(pos + 1);
372                 tagElems = document.getElementsByTagName(tag);
373                 tagElem = (Element JavaDoc) tagElems.item(0);
374                 cuurentLevel++;
375                 pos = subKey.indexOf("/");
376                 if (pos != -1) {
377                     while (pos != -1) {
378                         tag = subKey.substring(0, pos);
379                         subKey = subKey.substring(pos + 1);
380                         tagElems = tagElem.getElementsByTagName(tag);
381                         if (levelNodes != null
382                                 && cuurentLevel < levelNodes.length) {
383                             tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
384                         } else {
385                             tagElem = (Element JavaDoc) tagElems.item(0);
386                         }
387                         if (tagElem == null) {
388                             return;
389                         }
390                         cuurentLevel++;
391                         pos = subKey.indexOf("/");
392                     }
393                 }
394                 pos = subKey.indexOf("@");
395                 tag = subKey.substring(0, pos);
396                 if (pos != -1) {
397                     tagElems = tagElem.getElementsByTagName(tag);
398                     if (levelNodes != null && cuurentLevel < levelNodes.length) {
399                         tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
400                     } else {
401                         tagElem = (Element JavaDoc) tagElems.item(0);
402                     }
403                     String JavaDoc attrName = subKey.substring(pos + 1);
404
405                     tagElem.setAttribute(attrName, value);
406                 }
407             } else {
408                 pos = subKey.indexOf("@");
409                 tag = subKey.substring(0, pos);
410                 if (pos != -1) {
411                     tagElems = document.getElementsByTagName(tag);
412                     if (levelNodes != null && cuurentLevel < levelNodes.length) {
413                         tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
414                     } else {
415                         tagElem = (Element JavaDoc) tagElems.item(0);
416                     }
417                     String JavaDoc attrName = subKey.substring(pos + 1);
418
419                     tagElem.setAttribute(attrName, value);
420                 }
421             }
422         } catch (NullPointerException JavaDoc ex) {
423             throw new XmlUtilException(ex);
424         }
425     }
426
427     /**
428      * Return number of nodes defined by key parameter.
429      *
430      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
431      * (e.g. /doml/database).
432      *
433      * @return Number of nodes defined by key parameter.
434      *
435      */

436     public int getNumberOfNodes(String JavaDoc key) throws XmlUtilException {
437         return getNumberOfNodes(key, null);
438     }
439
440     /**
441      * Return number of nodes defined by key parameter.
442      *
443      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
444      * (e.g. /doml/database).
445      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
446      * (starting from level 0). These numbers tell to which appearance of specific
447      * tag key tag belongs to. It is not necessary to provide all tag levels.
448      *
449      * @return Number of nodes defined by key parameter.
450      *
451      */

452     public int getNumberOfNodes(String JavaDoc key, int levelNodes[]) throws XmlUtilException {
453         String JavaDoc nodeValue = "";
454         NodeList JavaDoc tagElems;
455         Element JavaDoc tagElem;
456         String JavaDoc tag;
457         String JavaDoc subKey;
458         int cuurentLevel = 0;
459         int pos = key.indexOf("/");
460
461         if (pos < 0) {
462             return 0;
463         }
464         if (pos == 0) { // cut leading separator "/"
465
subKey = key.substring(pos + 1);
466             pos = subKey.indexOf("/");
467         } else {
468             subKey = key;
469         }
470         try {
471             if (pos != -1) {
472                 tag = subKey.substring(0, pos);
473                 subKey = subKey.substring(pos + 1);
474                 tagElems = document.getElementsByTagName(tag);
475                 tagElem = (Element JavaDoc) tagElems.item(0);
476                 cuurentLevel++;
477                 pos = subKey.indexOf("/");
478                 if (pos != -1) {
479                     while (pos != -1) {
480                         tag = subKey.substring(0, pos);
481                         subKey = subKey.substring(pos + 1);
482                         tagElems = tagElem.getElementsByTagName(tag);
483                         if (levelNodes != null
484                                 && cuurentLevel < levelNodes.length) {
485                             tagElem = (Element JavaDoc) tagElems.item(levelNodes[cuurentLevel]);
486                         } else {
487                             tagElem = (Element JavaDoc) tagElems.item(0);
488                         }
489                         if (tagElem == null) {
490                             return 0;
491                         }
492                         cuurentLevel++;
493                         pos = subKey.indexOf("/");
494                     }
495                 }
496                 tagElems = tagElem.getElementsByTagName(subKey);
497                 return tagElems.getLength();
498             } else {
499                 tagElems = document.getElementsByTagName(subKey);
500                 return tagElems.getLength();
501             }
502         } catch (NullPointerException JavaDoc ex) {
503             throw new XmlUtilException(ex);
504         }
505     }
506
507     /**
508      * Return value of single text node defined by key parameter.
509      *
510      * @param xmlfile full path name of xml file which is about to be read.
511      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
512      * (e.g. /doml/database).
513      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
514      * (starting from level 0). These numbers tell to which appearance of specific
515      * tag key tag belongs to. It is not necessary to provide all tag levels.
516      *
517      * @return Value of single text node defined by key parameter or null if attribute doesn't exist.
518      *
519      * Example:
520      *
521      * In faculty.xml xmlfile:
522      * <faculty>
523      * <department name="electronics>
524      * <student>
525      * <name>Marko</name>
526      * </student>
527      * <student>
528      * <name>Ivana</name>
529      * </student>
530      * </department>
531      * <department name="computers">
532      * <student>
533      * <name>Zeljko</name>
534      * </student>
535      * <student>
536      * <name>Jelena</name>
537      * </student>
538      * <student>
539      * <name>Boris</name>
540      * </student>
541      * </department>
542      * </faculty>
543      *
544      * int levelNodes[] = {0,1,2};
545      * getSingleTextNode("faculty.xml","/faculty/department/student/name",levelNodes) will produce: Boris
546      *
547      * The same result will produce: int levelNodes[] = {0,1,2,0};
548      */

549     static public String JavaDoc getSingleTextNode(String JavaDoc xmlfile, String JavaDoc key, int levelNodes[]) throws XmlUtilException {
550         XmlUtil xml = new XmlUtil(xmlfile);
551
552         return xml.getSingleTextNode(key, levelNodes);
553     }
554
555     /**
556      * Return value of node attribute defined by key parameter.
557      *
558      * @param xmlfile full path name of xml file which is about to be read.
559      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
560      * (e.g. /doml/database).
561      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
562      * (starting from level 0). These numbers tell to which appearance of specific
563      * tag key tag belongs to. It is not necessary to provide all tag levels.
564      *
565      * @return Value of node attribute defined by key parameter or null if attribute doesn't exist.
566      *
567      * Example:
568      *
569      * In faculty.xml xmlfile:
570      * <faculty>
571      * <department name="electronics>
572      * <student>
573      * <name>Marko</name>
574      * </student>
575      * <student>
576      * <name>Ivana</name>
577      * </student>
578      * </department>
579      * <department name="computers">
580      * <student index="6403">
581      * <name>Zeljko</name>
582      * </student>
583      * <student>
584      * <name>Jelena</name>
585      * </student>
586      * <student>
587      * <name>Boris</name>
588      * </student>
589      * </department>
590      * </faculty>
591      *
592      * int levelNodes[] = {0,1,0};
593      * getSingleTextNode("faculty.xml","/faculty/department/student@index",levelNodes) will produce: 6403
594      */

595     static public String JavaDoc getSingleAttribute(String JavaDoc xmlfile, String JavaDoc key, int levelNodes[]) throws XmlUtilException {
596         XmlUtil xml = new XmlUtil(xmlfile);
597
598         return xml.getSingleAttribute(key, levelNodes);
599     }
600
601     /**
602      * Set and save value of attribute node defined by key parameter.
603      *
604      * @param xmlfile full path name of xml file which is about to be read.
605      * @param key Full name of tag attribute which is about to be read. The tags in the key
606      * are separated by "/". Name of the attribute is separated by "@" from tag name
607      * (e.g. /doml/database@templateset).
608      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
609      * (starting from level 0). These numbers tell to which appearance of specific
610      * tag key tag belongs to. It is not necessary to provide all tag levels.
611      * @param value New value of attribute node.
612      * @param prop Output properties for xml file.
613      */

614     static public void setSingleAttribute(String JavaDoc xmlfile, String JavaDoc key, int levelNodes[], String JavaDoc value, Properties JavaDoc prop)
615         throws XmlUtilException {
616         XmlUtil xml = new XmlUtil(xmlfile);
617
618         xml.setSingleAttribute(key, levelNodes, value);
619         xml.store(prop);
620     }
621
622     /**
623      * Return number of nodes defined by key parameter.
624      *
625      * @param xmlfile full path name of xml file which is about to be read.
626      * @param key Full name of tag which is about to be read. The tags in the key are separated by "/"
627      * (e.g. /doml/database).
628      * @param levelNodes Array of ordinal numbers. There is one number for each tag level
629      * (starting from level 0). These numbers tell to which appearance of specific
630      * tag key tag belongs to. It is not necessary to provide all tag levels.
631      *
632      * @return Number of nodes defined by key parameter.
633      *
634      * Example:
635      *
636      * In faculty.xml xmlfile:
637      * <faculty>
638      * <department name="electronics>
639      * <student>
640      * <name>Marko</name>
641      * </student>
642      * <student>
643      * <name>Ivana</name>
644      * </student>
645      * </department>
646      * <department name="computers">
647      * <student>
648      * <name>Zeljko</name>
649      * </student>
650      * <student>
651      * <name>Jelena</name>
652      * </student>
653      * <student>
654      * <name>Boris</name>
655      * </student>
656      * </department>
657      * </faculty>
658      *
659      * int levelNodes[] = {0,1};
660      * getSingleTextNode("faculty.xml","/faculty/department/student",levelNodes) will produce: 3
661      *
662      */

663     static public int getNumberOfNodes(String JavaDoc xmlfile, String JavaDoc key, int levelNodes[])
664         throws XmlUtilException {
665         XmlUtil xml = new XmlUtil(xmlfile);
666
667         return xml.getNumberOfNodes(key, levelNodes);
668     }
669
670     /*
671      * Test.
672      */

673     public static void main(String JavaDoc[] args) {
674         int levelNodes[] = {0, 0, 1};
675         String JavaDoc key = "/databaseManager/database/objectId@name";
676         String JavaDoc value = "webdocwf";
677
678         try {
679             XmlUtil xml = new XmlUtil("discRackDods.xml");
680
681             xml.setSingleAttribute(key, levelNodes, value);
682             System.out.println(key + " = "
683                     + xml.getSingleAttribute(key, levelNodes));
684             xml.store();
685         } catch (XmlUtilException e) {
686             e.printStackTrace();
687         }
688     }
689 }
690
Popular Tags