Java XML Node Sibiling getFirstSiblingNamed(Node node, String name)

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

Description

Returns the first sibling of node, or node itself, which has the given name.

License

Open Source License

Parameter

Parameter Description
node A node.
name The name of the node we are looking for.

Return

The first node whose name matches, or null.

Declaration

public static Node getFirstSiblingNamed(Node node, String name) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /**//from w ww.  j  a  v a2s  . c om
     * Returns the first sibling of <code>node</code>, or <code>node</code>
     * itself, which has the given name. If none is found, the function returns
     * <code>null</code>.
     * 
     * @param node
     *            A node.
     * @param name
     *            The name of the node we are looking for.
     * @return The first node whose name matches, or <code>null</code>.
     */
    public static Node getFirstSiblingNamed(Node node, String name) {
        while (node != null && !node.getNodeName().equals(name)) {
            node = node.getNextSibling();
        }

        return node;
    }
}

Related

  1. containsSiblings(org.w3c.dom.Node node)
  2. getFirstElementSibling(Node node)
  3. getFirstSiblingElmt(Node aNode)
  4. getLocHomoSibling(Node aNode)
  5. getNextElementSibling(Node node)
  6. getNextElementSibling(Node node)
  7. getNextElementSibling(Node node)