Java Utililty Methods XML Child Node Get

List of utility methods to do XML Child Node Get

Description

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

Method

ListgetChildNodesByName(Node element, String name, boolean caseSensitive)
Helper Method.
ArrayList<Node> nodes = new ArrayList<Node>();
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (caseSensitive) {
        if (node.getNodeName().equals(name))
            nodes.add(node);
    } else {
...
ListgetChildNodesByName(Node element, String name, boolean caseSensitive)
Helper Method.
ArrayList<Node> nodes = new ArrayList<Node>();
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (caseSensitive) {
        if (node.getNodeName().equals(name))
            nodes.add(node);
    } else {
...
ListgetChildNodesByName(Node node, String name)
get Child Nodes By Name
List<Node> result = new ArrayList<Node>();
NodeList childList = node.getChildNodes();
for (int i = 0; i < childList.getLength(); ++i) {
    Node child = childList.item(i);
    if (child.getNodeName().equals(name)) {
        result.add(child);
return result;
NodeListgetChildNodesByTagName(final Element element, final String tagName)
get Child Nodes By Tag Name
final List<Element> elements = getChildElementsByTagName(element, tagName);
return new NodeList() {
    @Override
    public Node item(final int index) {
        if (index >= elements.size()) {
            return null;
        return elements.get(index);
...
ListgetChildNodesWithName(Node node, String name)
get Child Nodes With Name
return getChildNodesWithName(node, name, null);
StringgetChildNodeText(Element element, String nodeTagName)
Returns the text of the child element identified by nodeTagName.
NodeList elements = element.getElementsByTagName(nodeTagName);
for (int j = 0; j < elements.getLength(); j++) {
    Node node = (Node) elements.item(j);
    NodeList elementsChild = node.getChildNodes();
    for (int k = 0; k < elementsChild.getLength(); k++) {
        Node node2 = (Node) elementsChild.item(k);
        if (node2.getNodeType() == Node.TEXT_NODE) {
            return node2.getNodeValue();
...
StringgetChildNodeText(Node root, String childName)
get Child Node Text
NodeList nodeList = root.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
    if (childName.equals(nodeList.item(i).getNodeName()))
        return nodeList.item(i).getTextContent();
return "";
StringgetChildNodeTextContent(Node parentNode, String childElementName)
get Child Node Text Content
Node node = getChildNode(parentNode, childElementName);
if (node != null)
    return node.getTextContent();
return null;
StringgetChildNodeTextContents(Node node, String name)
get Child Node Text Contents
Node tempNode = getChildNode(node, name);
if (tempNode != null)
    return (tempNode.getTextContent());
else
    return (null);
StringgetChildNodeValue(Element node, String tagName)
get Child Node Value
NodeList nodes = node.getElementsByTagName(tagName);
if (nodes.getLength() > 0) {
    return nodes.item(0).getTextContent().trim();
return null;