Java XML Element Get getElement(Element config, String elementName)

Here you can find the source of getElement(Element config, String elementName)

Description

returns the element with the given name

License

Open Source License

Declaration

public static Element getElement(Element config, String elementName) 

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 {
    /**// w ww .  j  a  v a  2  s  . c o m
     * returns the element with the given name
     */
    public static Element getElement(Element config, String elementName) {
        NodeList children = config.getChildNodes();
        Node node;
        for (int counter = 0; counter < children.getLength(); counter++) {
            node = children.item(counter);
            if (node instanceof Element) {
                if (((Element) node).getTagName().equals(elementName)) {
                    return ((Element) node);
                }
            }
        }
        return null;
    }
}

Related

  1. findElementList(String name, String attrName, String attrValue, Document doc)
  2. findElementOrContainer(Document document, Element parent, String element)
  3. getElement(Document doc, QName elementQName)
  4. getElement(Document doc, String path)
  5. getElement(Document pDocument, String psTagName, int index)
  6. getElement(Element config, String elementName)
  7. getElement(Element e, String localName)
  8. getElement(Element e, String name)
  9. getElement(Element e, String nsUri, String localName)