ca.infoway.messagebuilder.util.xml
Class NodeUtil

Package class diagram package NodeUtil
java.lang.Object
  extended by ca.infoway.messagebuilder.util.xml.NodeUtil

public class NodeUtil
extends Object

A variety of utility methods for manipulating nodes.

Author:
Intelliware Development

Constructor Summary
NodeUtil()
           
 
Method Summary
static List<Node> asList(NodeList children)
          Treat the NodeList as a standard list.
static List<Node> getChildNodes(Node node, String tagName)
          Get all children of a particular tag name as a list.
static String getLocalOrTagName(Node node)
          Get the local or tag name (depending on whether or not the DOM tree was parsed with namespace awareness.
static String getTextValue(Node node)
          Scan all immediate children of a node, and append all text nodes into a string.
static String getTextValue(Node node, boolean recurse)
          Scan all immediate children of a node, and append all text nodes into a string.
static List<Element> toElementList(Node node)
          Get all child elements of the given node as a list of elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeUtil

public NodeUtil()
Method Detail

getTextValue

public static String getTextValue(Node node)

Scan all immediate children of a node, and append all text nodes into a string. Consider the following example:

  <customer>Joe Schmoe</customer>
  

In this case, calling this method on the customer element returns "Joe Schmoe".

Parameters:
node - - the node to scan
Returns:
- the text string

getTextValue

public static String getTextValue(Node node,
                                  boolean recurse)

Scan all immediate children of a node, and append all text nodes into a string. Consider the following example:

  <customer>Joe Schmoe</customer>
  

In this case, calling this method on the customer element returns "Joe Schmoe".

Parameters:
node - - the node to scan
recurse - - a flag to indicate whether or not to recurse into sub-elements
Returns:
- the text string

asList

public static List<Node> asList(NodeList children)

Treat the NodeList as a standard list.

Parameters:
children - - the node list
Returns:
- the list of nodes

getChildNodes

public static List<Node> getChildNodes(Node node,
                                       String tagName)

Get all children of a particular tag name as a list.

Parameters:
node - - the parent node
tagName - - the tag name to select
Returns:
- the list of nodes

toElementList

public static List<Element> toElementList(Node node)

Get all child elements of the given node as a list of elements.

Parameters:
node - - the node
Returns:
- the list of child elements

getLocalOrTagName

public static String getLocalOrTagName(Node node)

Get the local or tag name (depending on whether or not the DOM tree was parsed with namespace awareness.

Parameters:
node - - the node/element
Returns:
- the local name, if it is not blank; the tag name otherwise.


Copyright © 2013. All Rights Reserved.