Java Utililty Methods XML Child Element Text

List of utility methods to do XML Child Element Text

Description

The list of methods to do XML Child Element Text are organized into topic(s).

Method

StringgetChildElementTextValue(Node parent, String name)
Returns the text value of a child element with the given name, of the given parent element, or null if the child does not exist or does not have a child text node
Element child = getChildElement(parent, name);
if (child == null) {
    return null;
Node textNode = child.getFirstChild();
if (textNode == null) {
    return null;
return textNode.getNodeValue();
StringgetChildElementValue(Element p_rootElement, String p_elementName)
get Child Element Value
Element element = getChildElement(p_rootElement, p_elementName);
if (element == null)
    return null;
return getElementValue(element);
StringgetChildElementValue(Element parent, String name)
Gets the value for the child Element with the indicated name.
Element elem;
if ((elem = firstChildElement(parent)) == null) {
    return null;
if (elem.getNodeName().equals(name)) {
    return elem.getFirstChild().getNodeValue();
while ((elem = nextSiblingElement(elem)) != null) {
...
StringgetChildElementValue(Element parentElm, String elementName, String defaultValue)
get Child Element Value
String value = getChildElementValue(parentElm, elementName);
if (value == null) {
    return defaultValue;
} else {
    return value;
StringgetChildElementValueByTagName(Element ele, String childEleName)
get Child Element Value By Tag Name
Element child = getChildElementByTagName(ele, childEleName);
return (child != null ? getTextValue(child) : null);
StringgetChildElementValueByTagName(Element ele, String childEleName)
Utility method that returns the first child element value identified by its name.
Element child = getChildElementByTagName(ele, childEleName);
return (child != null ? getTextValue(child) : null);
StringgetChildElementValueByTagName(Element parentElement, String childTag)
get Child Element Value By Tag Name
if (childTag.equals(parentElement.getNodeName())) {
    return getNodeValue(parentElement);
for (Node temp = parentElement.getFirstChild(); temp != null; temp = temp.getNextSibling()) {
    if (temp.getNodeType() == Node.ELEMENT_NODE && childTag.equals(temp.getNodeName())) {
        return getNodeValue(temp);
return null;
StringgetChildText(Element elem, String childTagName)
Return content of child element with given tag name.
NodeList nodeList = elem.getElementsByTagName(childTagName);
int len = nodeList.getLength();
if (len == 0) {
    return null;
return getElementText((Element) nodeList.item(len - 1));
StringgetChildText(Element element, String defaultValue)
Returns the child text of this element, or the default value if there is none.
Node childNode = element.getFirstChild();
if (childNode == null || !(childNode instanceof Text))
    return defaultValue;
return childNode.getNodeValue();
StringgetChildText(Element element, String nodeName)
Returns the textual content of the named child element, or null if there's no such child.
NodeList ndlist = element.getChildNodes();
Node nd;
String rtnVal = null;
for (int i = 0; i < ndlist.getLength(); i++) {
    nd = (Node) ndlist.item(i);
    if (nd.getNodeType() == Node.ELEMENT_NODE && nd.getNodeName().equals(nodeName)) {
        rtnVal = getText(nd);
        break;
...