de.umass.xml
Class DomElement

java.lang.Object
  extended by de.umass.xml.DomElement

public class DomElement
extends Object

DomElement wraps around an Element and provides convenience methods.

Author:
Janni Kovacs

Constructor Summary
DomElement(Element elem)
          Creates a new wrapper around the given Element.
 
Method Summary
 String getAttribute(String name)
          Returns the attribute value to a given attribute name or null if the attribute doesn't exist.
 DomElement getChild(String name)
          Returns the child element with the given name or null if it doesn't exist.
 List<DomElement> getChildren()
           
 List<DomElement> getChildren(String name)
          Returns all children of this element with the given tag name.
 String getChildText(String name)
          Returns the text content of a child node with the given name.
 Element getElement()
           
 String getTagName()
          Returns this element's tag name.
 String getText()
           
 boolean hasAttribute(String name)
          Tests if this element has an attribute with the specified name.
 boolean hasChild(String name)
          Checks if this element has a child element with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomElement

public DomElement(Element elem)
Creates a new wrapper around the given Element.

Parameters:
elem - An w3c Element
Method Detail

getElement

public Element getElement()
Returns:
the original Element

hasAttribute

public boolean hasAttribute(String name)
Tests if this element has an attribute with the specified name.

Parameters:
name - Name of the attribute.
Returns:
true if this element has an attribute with the specified name.

getAttribute

public String getAttribute(String name)
Returns the attribute value to a given attribute name or null if the attribute doesn't exist.

Parameters:
name - The attribute's name
Returns:
Attribute value or null

getText

public String getText()
Returns:
the text content of the element

hasChild

public boolean hasChild(String name)
Checks if this element has a child element with the given name.

Parameters:
name - The child's name
Returns:
true if this element has a child element with the given name

getChild

public DomElement getChild(String name)
Returns the child element with the given name or null if it doesn't exist.

Parameters:
name - The child's name
Returns:
the child element or null

getChildText

public String getChildText(String name)
Returns the text content of a child node with the given name. If no such child exists or the child does not have text content, null is returned.

Parameters:
name - The child's name
Returns:
the child's text content or null

getChildren

public List<DomElement> getChildren()
Returns:
all children of this element

getChildren

public List<DomElement> getChildren(String name)
Returns all children of this element with the given tag name.

Parameters:
name - The children's tag name
Returns:
all matching children

getTagName

public String getTagName()
Returns this element's tag name.

Returns:
the tag name