Java Utililty Methods XML Element Get by Name

List of utility methods to do XML Element Get by Name

Description

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

Method

ElementgetElementByTagName(Document doc, String eleName)
get Element By Tag Name
NodeList nl = doc.getElementsByTagName(eleName);
if (null == nl) {
    return null;
Node item = nl.item(0);
return (Element) item;
NodegetElementByTagName(Document document, String tagName)
get Element By Tag Name
if (document == null || tagName == null) {
    return null;
NodeList nodes = document.getElementsByTagName(tagName);
if (nodes == null || nodes.getLength() < 1) {
    return null;
return nodes.item(0);
...
ElementgetElementByTagName(Element aParent, String aName)
get Element By Tag Name
Node child = aParent.getFirstChild();
while (child != null) {
    if (child instanceof Element && ((Element) child).getTagName().equals(aName)) {
        return (Element) child;
    child = child.getNextSibling();
return null;
...
ElementgetElementByTagName(Element parent, String elementName)
get Element By Tag Name
NodeList nodeList = parent.getElementsByTagName(elementName);
if (nodeList.getLength() > 0) {
    return (Element) nodeList.item(0);
return null;
ElementgetElementByTagName(Element parent, String elementName)
Get a child element with a given tag name.
NodeList nodeList = parent.getElementsByTagName(elementName);
if (nodeList.getLength() > 0) {
    return (Element) nodeList.item(0);
return null;
ElementgetElementByTagNameWithParents(Element n, String... elementName)
Gets the first child Element with a given name
for (String elName : elementName) {
    Element subEl = getElementByTagName(n, elName);
    if (subEl == null)
        return null;
    n = subEl;
return n;
DategetElementDateValue(Document document, Element parent, String string)
get Element Date Value
return parseDate(getElementStringValue(document, parent, string));
floatgetElementFloatValue(Document document, Element parent, String element)
get Element Float Value
return Float.parseFloat(getElementStringValue(document, parent, element));
ListgetElements(Element parent, String localName)
get Elements
List<Element> result = new ArrayList<Element>();
Node child = parent.getFirstChild();
while (child != null) {
    if (child instanceof Element && child.getLocalName().equals(localName)) {
        result.add((Element) child);
    child = child.getNextSibling();
return result;
ListgetElements(Element parent, String localname, String namespaceURI)
Get the child elements having the supplied localname and namespace.
return getElements(parent.getChildNodes(), localname, namespaceURI);