Java XML NodeList getFirstElement(NodeList nodes)

Here you can find the source of getFirstElement(NodeList nodes)

Description

Returns the first node in the node list that is an element.

License

Open Source License

Parameter

Parameter Description
nodes The list of nodes that contains the element to be determined.

Return

The first element in the given node list.

Declaration

public static Node getFirstElement(NodeList nodes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**//  w w  w.jav  a2  s. c o m
     * Returns the first node in the node list that is an element.
     * 
     * @param nodes The list of nodes that contains the element to be
     *              determined.
     * 
     * @return The first element in the given node list.
     */
    public static Node getFirstElement(NodeList nodes) {
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                return node;
            }
        }
        return null;
    }
}

Related

  1. getElementsOfNodeList(NodeList nodeList)
  2. getEnvVariableMap(NodeList nodes)
  3. getFirst(NodeList nodes)
  4. getFirstElement(NodeList list)
  5. getFirstElement(NodeList list)
  6. GetFirstInstance(NodeList nList)
  7. getFirstNode(NodeList nodeList)
  8. getFirstNodeValue(NodeList nodeList)
  9. getFirstTextValueFromNodeList(NodeList nList)