Java XML Last Child Element getLastChild(Node node, String name)

Here you can find the source of getLastChild(Node node, String name)

Description

Gets the last child element of a node by name.

License

Open Source License

Parameter

Parameter Description
node Node.
name Name.

Return

Last child element with given tag name, or null if none found.

Declaration


public static Element getLastChild(Node node, String name) 

Method Source Code

//package com.java2s;
/*   Please see the license information at the end of this file. */

import org.w3c.dom.*;

public class Main {
    /**   Gets the last child element of a node by name.
     */*from ww w.j a  v  a2s. c om*/
     *   @param   node   Node.
     *
     *   @param   name   Name.
     *
     *   @return         Last child element with given tag name, or
     *               null if none found.
     */

    public static Element getLastChild(Node node, String name) {
        NodeList children = node.getChildNodes();
        int numChildren = children.getLength();
        for (int i = numChildren - 1; i >= 0; i--) {
            Node child = children.item(i);
            if (child.getNodeType() != Node.ELEMENT_NODE)
                continue;
            if (child.getNodeName().equals(name))
                return (Element) child;
        }
        return null;
    }
}

Related

  1. getLastChild(Element e)
  2. getLastChild(Element element)
  3. getLastChild(Element parent, String name)
  4. getLastChildElement(Element e)
  5. getLastChildElement(Element e)
  6. getLastChildElement(Element elem)
  7. getLastChildElement(Node n)