Java Utililty Methods XML Child Get

List of utility methods to do XML Child Get

Description

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

Method

ElementgetChild(Element parent, String name)
Returns the first child of specified Element with specified name.
for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (child instanceof Element && name.equals(child.getNodeName())) {
        return (Element) child;
return null;
ElementgetChild(Element parentEl, String name)
get Child
Element child = null;
List children = getChildren(parentEl, name);
if (children.size() > 0) {
    child = (Element) children.iterator().next();
return child;
ElementgetChild(Element root, String... path)
get Child
if (root == null || path.length == 0)
    return null;
Element element = root;
for (String tagName : path) {
    if (element == null)
        return null;
    NodeList list = element.getChildNodes();
    if (list == null || list.getLength() == 0)
...
ElementgetChild(final Element element, final String tagName)
get Child
final List<Element> children = getChildElementsByTagName(element, tagName);
if (children.isEmpty()) {
    return null;
if (children.size() > 1) {
    return null;
return children.get(0);
...
ElementgetChild(final Element parent, final String tag)
Get child node with given tag name.
if (parent == null || tag == null)
    return null;
final NodeList list = parent.getChildNodes();
for (int k = 0, listCount = list.getLength(); k < listCount; k++) {
    final Node child = list.item(k);
    if (child.getNodeType() == Node.ELEMENT_NODE && nodeNameEqualTo(child, tag))
        return (Element) child;
return null;
ElementgetChild(final Element root, final String name)
Return a named child relative to a supplied element.
if (null == root) {
    return null;
Element[] children = getChildren(root);
for (int i = 0; i < children.length; i++) {
    Element child = children[i];
    if (name.equals(child.getLocalName())) {
        return child;
...
ElementgetChild(final Element root, final String name)
Return a named child relative to a supplied element.
if (null == root)
    return null;
final NodeList list = root.getElementsByTagName(name);
final int n = list.getLength();
if (n < 1)
    return null;
return (Element) list.item(0);
NodegetChild(Node n, String name)
get Child
return getChildWithIndex(n, name, 0);
NodegetChild(Node node, String name)
get Child
if (!node.hasChildNodes())
    return null;
NodeList lst = node.getChildNodes();
if (lst == null)
    return null;
for (int i = 0; i < lst.getLength(); i++) {
    Node child = lst.item(i);
    if (name.equals(child.getNodeName()))
...
ElementgetChild(Node node, String name)
get Child
NodeList list = node.getChildNodes();
int count = list.getLength();
for (int i = 0; i < count; i++) {
    Node n = list.item(i);
    if (n.getNodeType() != Node.ELEMENT_NODE)
        continue;
    if (n.getNodeName().equalsIgnoreCase(name))
        return (Element) n;
...