com.calitha.xml
Class XMLUtil

java.lang.Object
  extended by com.calitha.xml.XMLUtil

public final class XMLUtil
extends Object

The XMLUtil class provides several convenience methods to work with XML and related documents.

Author:
Robert van Loenhout

Method Summary
static Element getChildElement(Element parent)
          Gets the first child element.
static Element getChildElement(Element parent, String tagName)
          Gets the first child element with a specified tag name
static List<Element> getChildElements(Element parent)
          Gets all child elements.
static List<Element> getChildElements(Element parent, String tagName)
          Gets the child elements.
static Element getLastChildElement(Element parent)
          Gets the last child element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getChildElements

public static List<Element> getChildElements(Element parent,
                                             String tagName)
Gets the child elements.

The child elements are selected by a specified tag name or all of them if tagName is null.

Parameters:
parent - element of which the children will be examined
tagName - tag name or null
Returns:
list of elements
Throws:
IllegalArgumentException - if the parent argument is null

getChildElements

public static List<Element> getChildElements(Element parent)
Gets all child elements.

Parameters:
parent - element of which the children will be examined
Returns:
list of elements
Throws:
IllegalArgumentException - if the parent argument is null

getChildElement

public static Element getChildElement(Element parent)
Gets the first child element.

Parameters:
parent - parent of which the first element will be selected
Returns:
child element or null if there is none
Throws:
IllegalArgumentException - if the parent argument is null

getLastChildElement

public static Element getLastChildElement(Element parent)
Gets the last child element.

Parameters:
parent - parent of which the last element will be selected
Returns:
child element or null if there is none
Throws:
IllegalArgumentException - if the parent argument is null

getChildElement

public static Element getChildElement(Element parent,
                                      String tagName)
Gets the first child element with a specified tag name

Parameters:
parent - parent of which the element will be selected
tagName - tag name or null if the first element should be selected
Returns:
element or null if not found
Throws:
IllegalArgumentException - if the parent argument is null