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

ElementgetElement(Document doc, String tagName, int index)
Return an Element given an XML document, tag name, and index
NodeList rows = doc.getDocumentElement().getElementsByTagName(tagName);
return (Element) rows.item(index);
ElementgetElement(Document doc, String tagName, int index)
get Element
return getElement(doc.getDocumentElement(), tagName, index);
ElementgetElement(Document document, Element parent, String element)
get Element
NodeList nl = parent.getElementsByTagName(element);
if (nl.getLength() == 0) {
    return null;
Node n = nl.item(0);
if (n == null) {
    return null;
return (Element) n;
ElementgetElement(Document document, String elementName)
get Element
return document.createElement(elementName);
ElementgetElement(Document owner, String elementName, String nsURI)
Returns the Element object corresponding to the given element name.
NodeList nodes = nsURI != null ? owner.getElementsByTagNameNS(nsURI, elementName)
        : owner.getElementsByTagName(elementName);
if (nodes != null && nodes.getLength() > 0) {
    return ((Element) nodes.item(0));
return (null);
ElementgetElement(Document parent, String name)
get Element
NodeList children = parent.getElementsByTagName(name);
if (children.getLength() >= 1)
    return (Element) children.item(0);
return null;
ElementgetElement(Element parent, String elementName)
Get the first instance of an element by name.
Element retval = null;
NodeList children = parent.getElementsByTagName(elementName);
if (children.getLength() > 0) {
    retval = (Element) children.item(0);
return retval;
ElementgetElement(Element parent, String elementName)
Get the first instance of an element by name.
Element retval = null;
NodeList children = parent.getElementsByTagName(elementName);
if (children.getLength() > 0) {
    retval = (Element) children.item(0);
return retval;
ElementgetElement(Element parent, String localname, int position)
Get the child element having the supplied localname, position and namespace.
return getElement(parent, localname, position, null);
ElementgetElement(Element parent, String tagName)
get Element
List<Element> children = getElements(parent, tagName);
if (children.isEmpty()) {
    return null;
return (Element) children.get(0);