metagloss 0.0.2

net.sf.metagloss.xml
Class DOMUtils

java.lang.Object
  extended by net.sf.metagloss.xml.DOMUtils

public class DOMUtils
extends java.lang.Object

Utility class for dealing with XML DOM data.


Method Summary
static java.lang.String getAttribute(org.w3c.dom.Element parent, java.lang.String child, java.lang.String attribute)
          Gets the attribute value of an element or its child element.
static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element parent, java.lang.String tag)
          Gets all requested child elements, one level deep.
static java.lang.String getData(org.w3c.dom.Element element, XMLBind bind)
          Gets the data associated with the XMLBinder in relation to the element.
static java.lang.String getText(org.w3c.dom.Element parent, java.lang.String child)
          Gets the text of an element or its child element.
static java.lang.String getTextOrNull(org.w3c.dom.Element parent, java.lang.String child)
          Gets the text of an element or its child element.
static boolean hasChild(org.w3c.dom.Element parent, java.lang.String child)
          Shorthand for checking if an element has any matching child elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getData

public static java.lang.String getData(org.w3c.dom.Element element,
                                       XMLBind bind)
                                throws XMLBindException
Gets the data associated with the XMLBinder in relation to the element.

Parameters:
element - Root element.
bind - Extraction binder.
Returns:
Requested attribute or element data.
Throws:
XMLBindException - If both bind's element and attribute data are empty.

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element parent,
                                            java.lang.String child,
                                            java.lang.String attribute)
                                     throws XMLBindException
Gets the attribute value of an element or its child element.

Parameters:
parent - Source element.
child - Child element, or null.
attribute - Attribute key.
Returns:
String representation of contents of attribute.
Throws:
XMLBindException - If child element doesn't exist.

getText

public static java.lang.String getText(org.w3c.dom.Element parent,
                                       java.lang.String child)
                                throws XMLBindException
Gets the text of an element or its child element.

Parameters:
parent - Source element.
child - Child element, or null.
Returns:
Contents of element.
Throws:
XMLBindException - If requested child element doesn't exist.

getTextOrNull

public static java.lang.String getTextOrNull(org.w3c.dom.Element parent,
                                             java.lang.String child)
Gets the text of an element or its child element.

Parameters:
parent - Source element.
child - Child element, or null.
Returns:
Contents of element, or null if requested child element doesn't exist.

hasChild

public static boolean hasChild(org.w3c.dom.Element parent,
                               java.lang.String child)
Shorthand for checking if an element has any matching child elements.

Parameters:
parent - Source element.
child - Search string.
Returns:
true if child elements exist.

getChildren

public static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element parent,
                                                              java.lang.String tag)
Gets all requested child elements, one level deep.

Parameters:
parent - Source.
tag - Child elements.
Returns:
Requested child elements.