Java Utililty Methods XML Last Child Element

List of utility methods to do XML Last Child Element

Description

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

Method

ElementgetLastChildElement(Node node)
Returns the last child element of the specified node, or null if there is no such element.
Node child = node.getLastChild();
while (child != null && child.getNodeType() != Node.ELEMENT_NODE) {
    child = child.getPreviousSibling();
return (Element) child;
ElementgetLastChildElement(Node parent)
Finds and returns the last child element node.
Node child = parent.getLastChild();
while (child != null) {
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) child;
    child = child.getPreviousSibling();
return null;
...
ElementgetLastChildElement(Node parent)
get Last Child Element
if (parent == null || parent.getChildNodes() == null) {
    return null;
NodeList nodes = parent.getChildNodes();
for (int i = nodes.getLength() - 1; i >= 0; i--) {
    Node child = nodes.item(i);
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) child;
...
ElementgetLastChildElement(Node start)
__UNDOCUMENTED__
NodeList children = start.getChildNodes();
if (children != null) {
    int len = children.getLength();
    Node n = null;
    for (int i = len - 1; i >= 0; i--) {
        n = children.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            return ((Element) n);
...
ElementgetLastChildElementNS(Node parent, String uri, String localpart)
Finds and returns the last child node with the given qualified name.
Node child = parent.getLastChild();
while (child != null) {
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        String childURI = child.getNamespaceURI();
        if (childURI != null && childURI.equals(uri) && child.getLocalName().equals(localpart)) {
            return (Element) child;
    child = child.getPreviousSibling();
return null;
ElementgetLastChildWithTagNameNS(Element parent, String namespaceURI, String localName)
get Last Child With Tag Name NS
final NodeList elements = parent.getElementsByTagNameNS(namespaceURI, localName);
return (elements.getLength() > 0) ? (Element) (elements.item(elements.getLength() - 1)) : null;
NodegetLastNamedChildNode(Node root, String nodeName)
get Last Named Child Node
Node current = root.getLastChild();
while (current != null) {
    if (current.getNodeName().equalsIgnoreCase(nodeName)) {
        return current;
    current = current.getPreviousSibling();
return null;
...
NodegetLastNodeChild(Node node)
Get the last non-text child of a node.
if (node == null)
    return null;
Node child = node.getLastChild();
while (child != null && child.getNodeType() == Node.TEXT_NODE)
    child = child.getPreviousSibling();
return child;
ElementgetLastVisibleChildElement(Node parent)
Finds and returns the last visible child element node.
Node child = parent.getLastChild();
while (child != null) {
    if (child.getNodeType() == Node.ELEMENT_NODE && !isHidden(child)) {
        return (Element) child;
    child = child.getPreviousSibling();
return null;
...