Java Utililty Methods XML Element Get

List of utility methods to do XML Element Get

Description

The list of methods to do XML Element Get are organized into topic(s).

Method

ElementgetElement(Element config, String elementName)
returns the first element with the given name, null if none exists.
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;
ElementgetElement(Element config, String elementName)
returns the element with the given name
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;
ElementgetElement(Element e, String localName)
get Element
return getElement(e, "", localName);
StringgetElement(Element e, String name)
get Element
if (e.getElementsByTagName(name) == null)
    return "";
if (e.getElementsByTagName(name).item(0) == null)
    return "";
return e.getElementsByTagName(name).item(0).getTextContent();
ElementgetElement(Element e, String nsUri, String localName)
get Element
NodeList l = e.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
    Node n = l.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        Element r = (Element) n;
        if (equals(r.getLocalName(), localName) && equals(fixNull(r.getNamespaceURI()), nsUri))
            return r;
return null;
ElementgetElement(Element el, String label)
get Element
NodeList l = el.getElementsByTagName(label);
if (l.getLength() < 1)
    return null;
return (Element) l.item(0);
ElementgetElement(Element el, String tagName, int index)
get Element
NodeList list = el.getElementsByTagName(tagName);
return (Element) list.item(index);
ElementgetElement(Element el, String... path)
get Element
for (int i = 0; i < path.length; i++) {
    el = getImmediateSubElement(el, path[i]);
    if (el == null)
        return null;
return el;
ElementgetElement(Element elem, String name)
get Element
NodeList nl = elem.getElementsByTagName(name);
if (nl.getLength() > 0)
    return (Element) nl.item(0);
else
    return null;
ElementgetElement(Element elem, String path)
Returns the named descendent.
List elems = getElements(elem, path);
if (elems.size() == 0)
    return null;
else
    return (Element) elems.get(0);