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

booleangetChildTextAsBoolean(Element parent, String childName, boolean defValue)
get Child Text As Boolean
try {
    String value = getChildText(parent, childName);
    if (value != null) {
        if (value.trim().equals("1")) {
            return true;
        if (value.trim().equals("0")) {
            return false;
...
BooleangetChildTextAsBooleanObj(Element parent, String childName, Boolean defValue)
Get the text content of a given child name as a java.lang.Boolean value.
try {
    String value = getChildText(parent, childName);
    if (value != null) {
        return Boolean.valueOf(value);
} catch (Exception ex) {
return defValue;
...
StringgetChildTextByName(Element parent, String name)
Equivalent to getTextContent(getFirstChildByName(e, n)), with a null check.
Element e = getFirstChildByName(parent, name);
return (e != null) ? getTextContent(e) : null;
StringgetChildTextByTagName(Element e, String tagName)
get Child Text By Tag Name
Element child = getChildByTagName(e, tagName);
if (child != null) {
    return getText(child);
return null;
StringgetChildTextContent(Element elemenet, String childElemenetName)
get Child Text Content
return org.springframework.util.xml.DomUtils.getChildElementValueByTagName(elemenet, childElemenetName);
StringgetChildTextContent(Element element, String childTagName)
Gets the text content of a child element for a tag name or null if not found.
Element childElem = getChildElementByTagName(element, childTagName);
return childElem == null ? null : childElem.getTextContent();
ListgetChildTextList(Element elem, String childTagName)
Return list of content Strings of all child elements with given tag name.
NodeList nodeList = elem.getElementsByTagName(childTagName);
int len = nodeList.getLength();
if (len == 0) {
    return Collections.EMPTY_LIST;
} else {
    List list = new ArrayList(len);
    for (int i = 0; i < len; i++) {
        list.add(getElementText((Element) nodeList.item(i)));
...
TextgetChildTextNode(Element el)
Gets the child text node containing character data for the given DOM element.
if (el == null)
    return null;
NodeList list = el.getChildNodes();
int size = list.getLength();
for (int i = 0; i < size; i++) {
    Node node = list.item(i);
    if (!(node instanceof Text))
        continue;
...
ListgetChildTextNodes(Element parent)
get Child Text Nodes
ArrayList<Text> retval = new ArrayList<Text>();
Node n = parent.getFirstChild();
while (n != null) {
    if (n instanceof Text) {
        retval.add((Text) n);
    n = n.getNextSibling();
return retval;
StringgetChildTextNodeValue(Node node)
Returns value of single child text node or null.
if (node.getChildNodes().getLength() != 1) {
    return null;
Node item0 = node.getChildNodes().item(0);
if (item0.getNodeType() != Node.TEXT_NODE) {
    return null;
return item0.getNodeValue();
...