Java XML Element Get getElementByTagName(Element current, String name)

Here you can find the source of getElementByTagName(Element current, String name)

Description

get Element By Tag Name

License

Apache License

Declaration

public static Element getElementByTagName(Element current, String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static Element getElementByTagName(Element current, String name) {
        return getElementByTagName(current, name, null);
    }// w w w . j a  v  a 2 s.c  o  m

    public static Element getElementByTagName(Element current, String name, String namespace) {

        NodeList elements = null;

        if (namespace == null)
            elements = current.getElementsByTagName(name);
        else
            elements = current.getElementsByTagNameNS(namespace, name);

        if (elements == null)
            return null;

        if (elements.getLength() != 1)
            return null;

        return (Element) elements.item(0);

    }
}

Related

  1. getElementByID(Element el, String id)
  2. getElementByID(Element el, String id)
  3. getElementById(Element element, String id)
  4. getElementByName(Element ele, String name)
  5. getElementByQualifiedName(Element n, String namespace, String elementName)
  6. getElementByTagName(Element el, String tag)
  7. getElementByTagName(Element el, String tag)
  8. getElementByTagName(Element elem, String name, String emptyValue)
  9. getElementByTagName(Element element, String name)