Java XML Node Parent getFirstElementByTagName(Node node, String tagName)

Here you can find the source of getFirstElementByTagName(Node node, String tagName)

Description

get First Element By Tag Name

License

Open Source License

Declaration

public static Element getFirstElementByTagName(Node node, String tagName) 

Method Source Code

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

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

public class Main {
    public static Element getFirstElementByTagName(Node node, String tagName) {
        for (int i = 0; i < node.getChildNodes().getLength(); i++) {
            Node n = node.getChildNodes().item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(tagName)) {
                return (Element) n;
            }//from  w ww.  j  a  v a2s  .  c  o m
        }
        return null;
    }
}

Related

  1. getFirstElement(Node element)
  2. getFirstElement(Node node, String namespace, String name)
  3. getFirstElement(Node xml)
  4. getFirstElementByTagName(Node node, String tagName)
  5. getFirstElementWithTagName(Node node, String element)
  6. getFirstNamedNode(Node node, String name)
  7. getFirstNodeByName(Node root, String tagName)