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(Element ele)
a utility method for finding the first child XML element of given XML element
Element resultEle = null;
NodeList childNodes = ele.getChildNodes();
if (childNodes != null) {
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            resultEle = (Element) node;
            break;
...
ElementgetFirstChildElement(Element elem)
Return the first child element of the given element.
for (Node n = elem.getFirstChild(); n != null; n = n.getNextSibling()) {
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) n;
return null;
ElementgetFirstChildElement(Element elem)
Return the first child element of the given element.
return (Element) findChildByType(elem, Node.ELEMENT_NODE);
ElementgetFirstChildElement(Element elem)
Return the first child element of the given element.
for (Node n = elem.getFirstChild(); n != null; n = n.getNextSibling()) {
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) n;
return null;
ElementgetFirstChildElement(Element element)
get First Child Element
if (element != null) {
    NodeList children = element.getChildNodes();
    int length = children.getLength();
    for (int i = 0; i < length; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE)
            return (Element) child;
return null;
ElementgetFirstChildElement(Element element)
Gets the first child element of an element
Node child = element.getFirstChild();
while (child != null && child.getNodeType() != Node.ELEMENT_NODE)
    child = child.getNextSibling();
return (Element) child;
ElementgetFirstChildElement(Element element)
get First Child Element
Node childNode = element.getFirstChild();
while (childNode != null) {
    if (childNode instanceof Element) {
        return (Element) childNode;
    childNode = childNode.getNextSibling();
return null;
...
ElementgetFirstChildElement(Element element)
Utility function for getting the first child element from a element
if (element == null) {
    throw new IllegalArgumentException("nullArgument: element");
for (Node currentChild = element.getFirstChild(); currentChild != null; currentChild = currentChild
        .getNextSibling()) {
    if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) currentChild;
return null;
ElementgetFirstChildElement(Element element)
Returns the first child element, or null if none exists.
for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
    if (node instanceof Element) {
        return (Element) node;
return null;
ElementgetFirstChildElement(Element element, String namespaceURI, String tagName)
Return the first element that is a child of 'element' with the name 'tagName'.
NodeList nl = element.getElementsByTagNameNS(namespaceURI, tagName);
if (nl != null && nl.getLength() > 0) {
    return (Element) nl.item(0);
return null;