org.apgrid.grpc.util
Class XMLUtil

java.lang.Object
  extended byorg.apgrid.grpc.util.XMLUtil

public class XMLUtil
extends java.lang.Object

Provides utility functions for parsing XML.


Constructor Summary
XMLUtil()
           
 
Method Summary
static int countChildNode(org.w3c.dom.Node node, java.lang.String name)
          Counts the number of a child node.
static java.lang.String getAttributeValue(org.w3c.dom.Node node, java.lang.String name)
          Gets attribute variables of the specified node.
static org.w3c.dom.Node getCdataNode(org.w3c.dom.Node node)
          Gets a CDATA node from the specified node.
static org.w3c.dom.Node getChildNode(org.w3c.dom.Node node, java.lang.String name)
          Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared at 1st will be returned.
static org.w3c.dom.Node getChildNode(org.w3c.dom.Node node, java.lang.String name, int occur)
          Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared in specified index will be returned.
static org.w3c.dom.Node getChildNodeGentle(org.w3c.dom.Node node, java.lang.String name)
          Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared at 1st will be returned.
This methods will not throw any Exception.
static org.w3c.dom.Node getNode(java.lang.String str)
          Gets XML node from specified string.
static java.lang.String getNodeValue(org.w3c.dom.Node node)
          Gets variable of the specified node.
static void printNode(org.w3c.dom.Node node, int level)
          Prints information of the specified node.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

getCdataNode

public static org.w3c.dom.Node getCdataNode(org.w3c.dom.Node node)
                                     throws NgXMLReadException
Gets a CDATA node from the specified node.

Parameters:
node - the specified node.
Returns:
a CDATA node node.
Throws:
NgXMLReadException - if can't find CDATA node.

getChildNodeGentle

public static org.w3c.dom.Node getChildNodeGentle(org.w3c.dom.Node node,
                                                  java.lang.String name)
Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared at 1st will be returned.
This methods will not throw any Exception.

Parameters:
node - the specified node.
name - a name of the child node.
Returns:
the child node when it is found, null otherwise.

getChildNode

public static org.w3c.dom.Node getChildNode(org.w3c.dom.Node node,
                                            java.lang.String name)
                                     throws NgXMLReadException
Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared at 1st will be returned.

Parameters:
node - the specified node.
name - a name of the child node.
Returns:
the child node.
Throws:
NgXMLReadException - if there are no specified node.

getChildNode

public static org.w3c.dom.Node getChildNode(org.w3c.dom.Node node,
                                            java.lang.String name,
                                            int occur)
                                     throws NgXMLReadException
Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared in specified index will be returned.

Parameters:
node - the specified node.
name - a name of the child node.
occur - specified index.
Returns:
the child node.
Throws:
NgXMLReadException - if there are no specified node.

countChildNode

public static int countChildNode(org.w3c.dom.Node node,
                                 java.lang.String name)
                          throws NgXMLReadException
Counts the number of a child node.

Parameters:
node - the specified node.
name - a name of the child node.
Returns:
the number of a child node.
Throws:
NgXMLReadException - if there are no specified node.

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Node node,
                                                 java.lang.String name)
                                          throws NgXMLReadException
Gets attribute variables of the specified node.

Parameters:
node - the specified node.
name - a name of the child node.
Returns:
attribute variables of the specified node.
Throws:
NgXMLReadException - if there are no attribute variable.

getNode

public static org.w3c.dom.Node getNode(java.lang.String str)
                                throws NgXMLReadException
Gets XML node from specified string.

Parameters:
str - XML string.
Returns:
XML node.
Throws:
NgXMLReadException - if there are any error when it's parsing XML string.

getNodeValue

public static java.lang.String getNodeValue(org.w3c.dom.Node node)
Gets variable of the specified node.

Parameters:
node - the specified node.
Returns:
variable of the specified node.

printNode

public static void printNode(org.w3c.dom.Node node,
                             int level)
Prints information of the specified node.

Parameters:
node - the specified node.
level - a number of indent.