Java XML Last Child Element getLastNodeChild(Node node)

Here you can find the source of getLastNodeChild(Node node)

Description

Get the last non-text child of a node.

License

Open Source License

Parameter

Parameter Description
node org.w3c.dom.Node The node

Return

org.w3c.dom.Node The last non-text child node of

Declaration

public static Node getLastNodeChild(Node node) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2003, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w  w  . j a va  2 s .c om*/
 * IBM Corporation - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Node;

public class Main {
    /**
     * Get the last non-text child of a node.
     * 
     * @return org.w3c.dom.Node The last non-text child node of
     * @node.
     * @param node
     *            org.w3c.dom.Node The node
     */
    public static Node getLastNodeChild(Node node) {
        if (node == null)
            return null;
        Node child = node.getLastChild();
        while (child != null && child.getNodeType() == Node.TEXT_NODE)
            child = child.getPreviousSibling();
        return child;
    }
}

Related

  1. getLastChildElement(Node parent)
  2. getLastChildElement(Node start)
  3. getLastChildElementNS(Node parent, String uri, String localpart)
  4. getLastChildWithTagNameNS(Element parent, String namespaceURI, String localName)
  5. getLastNamedChildNode(Node root, String nodeName)
  6. getLastVisibleChildElement(Node parent)