org.compass.core.util
Class DomUtils

java.lang.Object
  extended by org.compass.core.util.DomUtils

public abstract class DomUtils
extends Object

Convenience methods for working with the DOM API, in particular for working with DOM Nodes and DOM Elements.

Author:
kimchy
See Also:
Node, Element

Constructor Summary
DomUtils()
           
 
Method Summary
static List getChildElementsByTagName(Element ele, String childEleName)
          Retrieve all child elements of the given DOM element that match the given element name.
static List getChildElementsByTagName(Element ele, String childEleName, boolean localName)
          Retrieve all child elements of the given DOM element that match the given element name.
static String getElementAttribute(Element ele, String attributeName)
           
static String getElementAttribute(Element ele, String attributeName, String defaultValue)
          Gets the attribute value from the element.
static boolean getElementAttributeAsBoolean(Element ele, String attributeName, boolean defaultValue)
           
static String getTextValue(Element valueEle)
          Extract the text value from the given DOM element, ignoring XML comments.
static String getTrimmedTextValue(Element valueEle)
          Retruns the trimmed text value of the DOM element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomUtils

public DomUtils()
Method Detail

getElementAttribute

public static String getElementAttribute(Element ele,
                                         String attributeName)

getElementAttribute

public static String getElementAttribute(Element ele,
                                         String attributeName,
                                         String defaultValue)
Gets the attribute value from the element. If the attribute is null or is an empty string, will return the defaultValue.


getElementAttributeAsBoolean

public static boolean getElementAttributeAsBoolean(Element ele,
                                                   String attributeName,
                                                   boolean defaultValue)

getChildElementsByTagName

public static List getChildElementsByTagName(Element ele,
                                             String childEleName)
Retrieve all child elements of the given DOM element that match the given element name. Only look at the direct child level of the given element; do not go into further depth (in contrast to the DOM API's getElementsByTagName method).

Parameters:
ele - the DOM element to analyze
childEleName - the child element name to look for
Returns:
a List of child org.w3c.dom.Element instances
See Also:
Element, Element.getElementsByTagName(java.lang.String)

getChildElementsByTagName

public static List getChildElementsByTagName(Element ele,
                                             String childEleName,
                                             boolean localName)
Retrieve all child elements of the given DOM element that match the given element name. Only look at the direct child level of the given element; do not go into further depth (in contrast to the DOM API's getElementsByTagName method).

Can select whether or not to compare against the local name of the Element

Parameters:
ele - the DOM element to analyze
childEleName - the child element name to look for
localName - whether to compare against the local node name
Returns:
a List of child org.w3c.dom.Element instances
See Also:
Element, Element.getElementsByTagName(java.lang.String)

getTrimmedTextValue

public static String getTrimmedTextValue(Element valueEle)
Retruns the trimmed text value of the DOM element.

See Also:
getTextValue(org.w3c.dom.Element)

getTextValue

public static String getTextValue(Element valueEle)
Extract the text value from the given DOM element, ignoring XML comments.

Appends all CharacterData nodes and EntityReference nodes into a single String value, excluding Comment nodes.

See Also:
CharacterData, EntityReference, Comment


Copyright (c) 2004-2008 The Compass Project.