edu.umbc.cs.daml4jess
Class XmlUtil

java.lang.Object
  |
  +--edu.umbc.cs.daml4jess.XmlUtil

public class XmlUtil
extends java.lang.Object

XML untility class. It has some utility method such as obtaining the text value of a node, printing the tree structure of a document, etc.


Constructor Summary
XmlUtil()
           
 
Method Summary
static java.util.List getChildElementsByName(org.w3c.dom.Node parent, java.lang.String tagName)
          Get the list of direct child element nodes with the given tag name.
static org.w3c.dom.Element getFirstChildElementByName(org.w3c.dom.Node parent, java.lang.String tagName)
          Find the first direct child element with given tagName.
static java.lang.String getFirstChildValueByName(org.w3c.dom.Node parent, java.lang.String tagName)
          Get the value for the first direct child element node with the given tag name.
static java.lang.String getNodeValue(org.w3c.dom.Node node)
          Get the value of the given node.
static void printTree(org.w3c.dom.Document doc)
          Print the given xml document tree.
static void printTree(org.w3c.dom.Node root, int level)
          Recursively print the given xml document node.
 
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

getChildElementsByName

public static java.util.List getChildElementsByName(org.w3c.dom.Node parent,
                                                    java.lang.String tagName)
Get the list of direct child element nodes with the given tag name.

Returns:
a List of direct child element nodes that have type tagName; return null if no such nodes exist.

getFirstChildValueByName

public static java.lang.String getFirstChildValueByName(org.w3c.dom.Node parent,
                                                        java.lang.String tagName)
Get the value for the first direct child element node with the given tag name.

Returns:
the value for the first direct child element with the tagName. return null if no such a child node exist.
See Also:
on how the value is computed.

getFirstChildElementByName

public static org.w3c.dom.Element getFirstChildElementByName(org.w3c.dom.Node parent,
                                                             java.lang.String tagName)
Find the first direct child element with given tagName. Return null if no such node exists.

Parameters:
parent - the node whose child element will be search.
tagName - name of the node to be found from the parent's direct children.
Returns:
the first direct child element node with given tagName; return null if no such node exists.

getNodeValue

public static java.lang.String getNodeValue(org.w3c.dom.Node node)
Get the value of the given node. The value is computed by concatenating the values of all "leaf" descendant nodes.

Parameters:
node - the node whose value will be calculated.
Returns:
value of the given node; return an empty string if no valid value is associated with it.

printTree

public static void printTree(org.w3c.dom.Document doc)
Print the given xml document tree. Intended for for debug use only.

Parameters:
doc - the document which will be printed out.

printTree

public static void printTree(org.w3c.dom.Node root,
                             int level)
Recursively print the given xml document node. Intended for debug use only.

Parameters:
level - current level (from root node).