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

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

Description

returns the first element with the given name, null if none exists.

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.NodeList;

public class Main {
    /**//from   ww  w  .jav  a 2  s .c o  m
     * returns the first element with the given name, null if none exists.
     */
    public static Element getElement(Element config, String elementName) {
        NodeList children = config.getChildNodes();
        for (int counter = 0; counter < children.getLength(); counter++) {
            if (children.item(counter) instanceof Element) {
                Element el = (Element) children.item(counter);
                if (el.getTagName().equals(elementName)) {
                    return el;
                }
            }
        }
        return null;
    }
}

Related

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