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

NodegetChildNodeGentle(Node node, String namespace, String localname)
Gets specified child node from the specified node.
If there are several nodes which have same name, the node which was appeared at 1st will be returned.
This methods will not throw any Exception.
int count = 0;
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node tmp = list.item(i);
    if (nodeIsElementOf(tmp, namespace, localname)) {
        return tmp;
return null;
ArrayListgetChildNodeListByTagName(Element parent, String tagName)
get Child Node List By Tag Name
ArrayList<Element> lst = new ArrayList();
traverseNodes(parent, tagName, lst);
return lst;
ListgetChildNodes(Element ele)
get Child Nodes
List<Element> elements = new ArrayList<Element>();
if (ele == null) {
    return elements;
NodeList nl = ele.getChildNodes();
if (nl != null && nl.getLength() > 0) {
    for (Integer i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
...
ListgetChildNodes(final Node node)
get Child Nodes
final NodeList list = node.getChildNodes();
final List<Node> result = Lists.newArrayList();
for (int i = 0; i < list.getLength(); i++) {
    final Node child = list.item(i);
    result.add(child);
return result;
ListgetChildNodes(final Node node, final short nodetype)
Gets the given node's children of the given type.
final List<Node> result = new ArrayList<Node>();
final NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    final Node child = children.item(i);
    if (child.getNodeType() == nodetype) {
        result.add(child);
return result;
Node[]getChildNodes(final Node node, final String attributeName, final String value)
get Child Nodes
final ArrayList nodeList = new ArrayList();
final NodeList childs = node.getChildNodes();
String readValue = null;
for (int i = 0; i < childs.getLength(); i++) {
    readValue = getAttribute(childs.item(i), attributeName);
    if (value.equals(readValue)) {
        nodeList.add(childs.item(i));
final Node[] result = new Node[nodeList.size()];
nodeList.toArray(result);
return result;
ListgetChildNodes(final Node node, short... types)
Returns the child nodes of the passed node where the type of the child node is in the passed array of type codes
if (node == null)
    return Collections.emptyList();
if (types == null || types.length == 0)
    return Collections.emptyList();
final List<Node> nodes = new ArrayList<Node>();
for (Node n : nodeListToList(node.getChildNodes())) {
    if (Arrays.binarySearch(types, n.getNodeType()) >= 0) {
        nodes.add(n);
...
ListgetChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames)
Scans a node and all of its children for nodes of a particular type.
final List<Node> nodes = new ArrayList<Node>();
final NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
    final Node child = children.item(i);
    for (final String nodeName : nodeNames) {
        if (child.getNodeName().equals(nodeName)) {
            nodes.add(child);
        if (recursiveSearch) {
            nodes.addAll(getChildNodes(child, true, nodeName));
return nodes;
ListgetChildNodes(Node node)
Helper method to get a list of only Text and Element typed Node s.
List<Node> children = new ArrayList<Node>();
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    Node child = nl.item(i);
    short type = child.getNodeType();
    if (type == Node.ELEMENT_NODE) {
        children.add(child);
    } else if (type == Node.TEXT_NODE) {
...
ListgetChildNodes(Node node)
Method that returns a only the Element childs of a Node
return getNodeList(node.getChildNodes());