Java XML Node Find findElementNodeByName(Node node, String name)

Here you can find the source of findElementNodeByName(Node node, String name)

Description

find Element Node By Name

License

Open Source License

Declaration

public static Element findElementNodeByName(Node node, String name) 

Method Source Code

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

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

public class Main {
    public static Element findElementNodeByName(Node node, String name) {
        if (node == null) {
            return null;
        }//from   ww w  .java  2 s.c o  m
        NodeList nodeList = node.getChildNodes();
        if (nodeList == null || nodeList.getLength() == 0) {
            return null;
        }

        for (int i = 0; i < nodeList.getLength(); i++) {
            Node item = nodeList.item(i);
            if (item != null
                    && (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE)
                    && name.equalsIgnoreCase(item.getNodeName())) {
                return (Element) item;
            } else {
                Element element = findElementNodeByName(item, name);
                if (element != null) {
                    return element;
                }
            }
        }
        return null;
    }
}

Related

  1. findElement(Node startNode, String name, String namespace)
  2. findElementById(Node head, String id)
  3. findElementById(Node node, String id)
  4. findElementByName(Node node, final String name)
  5. findElementByTag(Set nodes, String tag)
  6. findElements(Node fromnode, String name)
  7. findElementsByName(Node node, List elements, String name)
  8. findNode(Document source, Element n)
  9. findNode(Node aNode, String aName)