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

ElementgetElementByName(Element ele, String name)
Get child element by name, ignoring namespace declarations
List<Element> list = getElementsByName(ele, name);
if (list.size() > 0)
    return list.get(0);
return null;
ElementgetElementByQualifiedName(Element n, String namespace, String elementName)
Gets the first child Element with a given name
NodeList subNodes = n.getElementsByTagNameNS(namespace, elementName);
int sz = subNodes.getLength();
if (sz > 0) {
    return (Element) subNodes.item(0);
return null;
ElementgetElementByTagName(Element current, String name)
get Element By Tag Name
return getElementByTagName(current, name, null);
ElementgetElementByTagName(Element el, String tag)
get Element By Tag Name
NodeList nl = el.getElementsByTagName(tag);
if (nl.getLength() > 0) {
    return (Element) nl.item(0);
return null;
ElementgetElementByTagName(Element el, String tag)
Gets the element by tag name.
NodeList nl = el.getElementsByTagName(tag);
if (nl.getLength() > 0) {
    return (Element) nl.item(0);
return null;
StringgetElementByTagName(Element elem, String name, String emptyValue)
Get text data of first XML org.w3c.dom.Element of given name.
NodeList nodeList = elem.getElementsByTagName(name);
if (nodeList.getLength() == 0) {
    return null;
NodeList children = nodeList.item(0).getChildNodes();
if (children.getLength() == 0 || children.item(0).getNodeType() != Node.TEXT_NODE) {
    return emptyValue;
return children.item(0).getNodeValue();
ElementgetElementByTagName(Element element, String name)
get Element By Tag Name
NodeList nodes = element.getElementsByTagName(name);
if (nodes.getLength() == 0)
    return null;
else
    return (Element) nodes.item(0);
ElementgetElementByTagName(Element element, String name, int index)
get Element By Tag Name
NodeList list = element.getElementsByTagName(name);
return (Element) list.item(index);
ElementgetElementByTagName(Element element, String tag)
get single element by tag name
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (node instanceof Element && ((Element) node).getTagName().equals(tag)) {
        return (Element) node;
return null;
...
ElementgetElementByTagName(Element element, String tag)
get single element by tag name.
NodeList list = element.getElementsByTagName(tag);
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (node instanceof Element) {
        return (Element) node;
return null;
...