Java XML Node Parent getFirstNodeByName(Node root, String tagName)

Here you can find the source of getFirstNodeByName(Node root, String tagName)

Description

get First Node By Name

License

Open Source License

Declaration

public static Node getFirstNodeByName(Node root, String tagName) 

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 {
    public static Node getFirstNodeByName(Node root, String tagName) {
        NodeList nodes;/*from w ww.j a  va  2  s  .c  o m*/

        nodes = root.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node n = nodes.item(i);
            if (n.getNodeName().equals(tagName)) {
                return n;
            }
        }
        return null;
    }
}

Related

  1. getFirstElement(Node xml)
  2. getFirstElementByTagName(Node node, String tagName)
  3. getFirstElementByTagName(Node node, String tagName)
  4. getFirstElementWithTagName(Node node, String element)
  5. getFirstNamedNode(Node node, String name)
  6. getFirstValidNode(Node node)
  7. getParent(Element elem)
  8. getParent(Element elem)
  9. getParent(final Node n)