Example usage for org.w3c.dom Node getNextSibling

List of usage examples for org.w3c.dom Node getNextSibling

Introduction

In this page you can find the example usage for org.w3c.dom Node getNextSibling.

Prototype

public Node getNextSibling();

Source Link

Document

The node immediately following this node.

Usage

From source file:Main.java

public static Node getNextHomoSibling(Node aNode) {
    Node nextSibling = aNode;
    while ((nextSibling = nextSibling.getNextSibling()) != null) {
        if (nextSibling.getNodeName().equals(aNode.getNodeName())) {
            return nextSibling;
        }//from   w w w  . j av a  2  s.c om
    }
    return null;
}

From source file:Main.java

/**
 * Get the next sibling Element of the supplied node.
 *
 * @param node The DOM Node.//from w w  w  .jav a  2s .c  om
 * @return The next sibling element
 */
public static Element getNextSiblingElement(Node node) {
    Node sibling = node.getNextSibling();
    while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) {
        sibling = sibling.getNextSibling();
    }
    return (Element) sibling;
}

From source file:Main.java

/**
 * Gets the next sibling Element of the node, skipping any Text nodes such as whitespace.
 * /*from   w w  w . ja  v a 2  s .c  o m*/
 * @param n The sibling to start with
 * @return The next sibling Element of n, or null if none
 */
public static Element getNextSiblingElement(Node n) {
    Node sib = n.getNextSibling();
    while (sib != null && sib.getNodeType() != Node.ELEMENT_NODE) {
        sib = sib.getNextSibling();
    }

    if (sib != null) {
        return (Element) sib;
    } else {
        return null;
    }
}

From source file:Main.java

public static Element getNextSiblingElement(Node node, final String siblingName) {
    do {// w  w  w.java  2s  .  c  om
        node = node.getNextSibling();
        if (node == null)
            return null;
    } while (node.getNodeType() != Node.ELEMENT_NODE || !node.getNodeName().equals(siblingName));
    return (Element) node;
}

From source file:Main.java

public static Element findNextElementWithAttribute(Node ret, String name, String attribute, String value) {
    ret = ret.getNextSibling();
    while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name)
            || ((Element) ret).getAttribute(attribute) == null
            || !((Element) ret).getAttribute(attribute).equals(value))) {
        ret = ret.getNextSibling();/*w  w w.  j a va  2 s .  c  om*/
    }
    return (Element) ret;
}

From source file:DOMHelper.java

/**
 * Gets the next sibling of a node that is an element.
 * @param node the node// w  ww.j  a v  a 2  s  .c  o  m
 * @return the next sibling element or {@code null} if none
 * @throws NullPointerException if {@code node} is {@code null}
 */
public static Element getNextSiblingElement(Node node) {
    do {
        node = node.getNextSibling();
    } while (node != null && node.getNodeType() != Node.ELEMENT_NODE);

    return (Element) node;
}

From source file:Utils.java

/**
 * Search our next siblings for a given node
 * @param currentNode Starting point for our search
 * @param tagName Node name to look up/*from ww w.j  a v  a2 s .co m*/
 * @return matching Node (null if none)
 */
public static Node getNextSiblingByName(Node currentNode, String tagName) {
    Node node = currentNode.getNextSibling();

    while ((node != null) && (!node.getNodeName().equals(tagName))) {
        node = node.getNextSibling();
    }
    return node;
}

From source file:Main.java

/**gets the sibling element of a node
 * @param start the node to get the sibling of
 * @return the sibling node*//*from  ww w .j av a2 s .  c  o  m*/
public static Node GetNextSiblingElement(Node start) {
    if (start == null)
        return start;
    Node node = start.getNextSibling();
    if (node == null)
        return node;
    else if (node.getNodeType() != Node.ELEMENT_NODE)
        return GetNextSiblingElement(node);
    else
        return node;
}

From source file:Main.java

/** Finds and returns the next sibling element node. */
public static Element getNextSiblingElement(Node node) {

    // search for node
    Node sibling = node.getNextSibling();
    while (sibling != null) {
        if (sibling.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) sibling;
        }//from w w w  .  j  av a2s  .com
        sibling = sibling.getNextSibling();
    }

    // not found
    return null;

}

From source file:Main.java

/**
 * @param n The current XML node/*from w w w. j  a va 2s  . co m*/
 * @return The next sibling that is a {@link Node#ELEMENT_NODE}.
 */
public static Node nextElementNode(Node n) {
    if (isElementNode(n))
        n = n.getNextSibling();

    while (n != null && !isElementNode(n))
        n = n.getNextSibling();

    return n;
}