Java Utililty Methods XML First Child Element

List of utility methods to do XML First Child Element

Description

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

Method

ElementgetFirstChildElement(Node parent)
get First Child Element
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); ++i)
    if (children.item(i) instanceof Element)
        return (Element) children.item(i);
return null;
ElementgetFirstChildElement(Node parent)
Return the first child element
if (parent != null) {
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (isElement(child)) {
            return (Element) child;
return null;
ElementgetFirstChildElement(Node parent)
Gets the first child element of a node.
NodeList nodeList = parent.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node instanceof Element) {
        return (Element) node;
return null;
...
ElementgetFirstChildElement(Node parent)
Get the first child element
NodeList childs = parent.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
    Node child = childs.item(i);
    if (child instanceof Element) {
        return (Element) child;
return null;
...
ElementgetFirstChildElement(Node parent)
get First Child Element
if (parent == null || parent.getChildNodes() == null) {
    return null;
NodeList nodes = parent.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
    Node child = nodes.item(i);
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) child;
...
ElementgetFirstChildElement(Node parent)
Returns a node's first child node that is an element.
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node n = children.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) n;
return null;
...
ElementgetFirstChildElement(Node rootNode)
Gets the first child org.w3c.dom.Element of the given Node.
if (rootNode == null) {
    return null;
Node node = rootNode.getFirstChild();
while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
    node = node.getNextSibling();
if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
...
ElementgetFirstChildElement(Node start)
gets the first child of a node which is an element.
Node n = null;
NodeList nl = start.getChildNodes();
int len = nl.getLength();
if (len == 0) {
    return null;
for (int i = 0; i < len; i++) {
    n = nl.item(i);
...
ElementgetFirstChildElementByLocalName(Element parentElem, String localName)
get First Child Element By Local Name
Node child = parentElem.getFirstChild();
while (child != null) {
    if ((child.getNodeType() == Node.ELEMENT_NODE) && getLocalName(child).equals(localName)) {
        return (Element) child;
    child = child.getNextSibling();
return null;
...
ElementgetFirstChildElementByName(Element parent, String tagName)
Return the first child element for the given tag name
List<Element> elementList = getChildElementsByName(parent, tagName);
if (!elementList.isEmpty())
    return elementList.get(0);
else
    return null;