Package de.umass.xml
Class DomElement
- java.lang.Object
-
- de.umass.xml.DomElement
-
public class DomElement extends java.lang.Object
DomElement
wraps around anElement
and provides convenience methods.- Author:
- Janni Kovacs
-
-
Constructor Summary
Constructors Constructor Description DomElement(org.w3c.dom.Element elem)
Creates a new wrapper around the givenElement
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAttribute(java.lang.String name)
Returns the attribute value to a given attribute name ornull
if the attribute doesn't exist.DomElement
getChild(java.lang.String name)
Returns the child element with the given name ornull
if it doesn't exist.java.util.List<DomElement>
getChildren()
java.util.List<DomElement>
getChildren(java.lang.String name)
Returns all children of this element with the given tag name.java.lang.String
getChildText(java.lang.String name)
Returns the text content of a child node with the given name.org.w3c.dom.Element
getElement()
java.lang.String
getTagName()
Returns this element's tag name.java.lang.String
getText()
boolean
hasAttribute(java.lang.String name)
Tests if this element has an attribute with the specified name.boolean
hasChild(java.lang.String name)
Checks if this element has a child element with the given name.
-
-
-
Method Detail
-
getElement
public org.w3c.dom.Element getElement()
- Returns:
- the original Element
-
hasAttribute
public boolean hasAttribute(java.lang.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 java.lang.String getAttribute(java.lang.String name)
Returns the attribute value to a given attribute name ornull
if the attribute doesn't exist.- Parameters:
name
- The attribute's name- Returns:
- Attribute value or
null
-
getText
public java.lang.String getText()
- Returns:
- the text content of the element
-
hasChild
public boolean hasChild(java.lang.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(java.lang.String name)
Returns the child element with the given name ornull
if it doesn't exist.- Parameters:
name
- The child's name- Returns:
- the child element or
null
-
getChildText
public java.lang.String getChildText(java.lang.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 java.util.List<DomElement> getChildren()
- Returns:
- all children of this element
-
getChildren
public java.util.List<DomElement> getChildren(java.lang.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 java.lang.String getTagName()
Returns this element's tag name.- Returns:
- the tag name
-
-