org.txml
Class XMLUtil

java.lang.Object
  |
  +--org.txml.XMLUtil

public class XMLUtil
extends java.lang.Object

Set of useful utility functions


Constructor Summary
XMLUtil()
           
 
Method Summary
static java.lang.String[] selectAllValues(XMLNode tree, java.lang.String select)
           Utility function to select all values from the XML tree (an array of values is returned).
static java.lang.String selectOneValue(XMLNode tree, java.lang.String select)
           Utility function to select one value from the XML tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

selectOneValue

public static java.lang.String selectOneValue(XMLNode tree,
                                              java.lang.String select)

Utility function to select one value from the XML tree. If search returns zero nodes, null is returned. If search returns multiple nodes, the value of the first one will be returned. If first selected node does not have a value, return is null.

Useful for retrieving one particular node value. Example:

   <title>
     <font>
        Lucida-bold
     </font>
     <color>
        Green
     </color>
     <icon>
        icons/icon-image.bmp
     </icon>
   </title>
 
Following code:
 ...
 XMLNode tree = ... // create or obtain xml tree

 String value = XMLUtil.selectOneValue(tree, "/title/color");
 
will return string "Green".


selectAllValues

public static java.lang.String[] selectAllValues(XMLNode tree,
                                                 java.lang.String select)

Utility function to select all values from the XML tree (an array of values is returned). Array elements may be null (if corresponding selected node does not have any value.

Usefult for retrieving arrays of data. Example:

   <animated-button>
     <image>
       images/button1.gif
     </image>
     <image>
       images/button2.gif
     </image>
     <image>
       images/button3.gif
     </image>
   </animated-button>
 
Following code:
 ...
 XMLNode tree = ... // create or obtain xml tree

 String [] value = XMLUtil.selectAllValues(tree, "/animated-button/image");
 
will return string array
   {
     "images/button1.gif",
     "images/button2.gif",
     "images/button3.gif"
   };