Java XML Element Get by Name getElement(Document document, Element parent, String element)

Here you can find the source of getElement(Document document, Element parent, String element)

Description

get Element

License

Apache License

Declaration

public static Element getElement(Document document, Element parent, String element) 

Method Source Code

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

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

public class Main {
    public static Element getElement(Document document, Element parent, String element) {
        NodeList nl = parent.getElementsByTagName(element);
        if (nl.getLength() == 0) {
            return null;
        }// w w w .  j a  v a 2s  . com

        Node n = nl.item(0);
        if (n == null) {
            return null;
        }

        return (Element) n;
    }
}

Related

  1. getElement(Document doc, String tagName, int index)
  2. getElement(Document doc, String tagName, int index)
  3. getElement(Document document, String elementName)
  4. getElement(Document owner, String elementName, String nsURI)
  5. getElement(Document parent, String name)
  6. getElement(Element parent, String elementName)