Java Utililty Methods XML Node Sibiling

List of utility methods to do XML Node Sibiling

Description

The list of methods to do XML Node Sibiling are organized into topic(s).

Method

ElementgetNextSiblingElement(Node node)
Returns the next sibling element of a Node.
Node sibling = node.getNextSibling();
while ((sibling != null) && (sibling.getNodeType() != Node.ELEMENT_NODE)) {
    sibling = sibling.getNextSibling();
return (Element) sibling;
ElementgetNextSiblingElement(Node node)
get Next Sibling Element
Node n = node.getNextSibling();
while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
    n = n.getNextSibling();
return (Element) n;
ElementgetNextSiblingElement(Node node, String elemNames[])
Finds and returns the next sibling node with the given name.
Node sibling = node.getNextSibling();
while (sibling != null) {
    if (sibling.getNodeType() == Node.ELEMENT_NODE) {
        for (int i = 0; i < elemNames.length; i++) {
            if (sibling.getNodeName().equals(elemNames[i])) {
                return (Element) sibling;
    sibling = sibling.getNextSibling();
return null;
NodeGetNextSiblingElement(Node start)
gets the sibling element of a node
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
...
ElementgetNextSiblingElementByName(Node node, String name)
Get the sibling Element of the supplied node that matches a given tag name.
Node sibling = node.getNextSibling();
while (sibling != null) {
    if (sibling.getNodeType() == Node.ELEMENT_NODE && sibling.getLocalName() != null
            && sibling.getLocalName().equals(name)) {
        return (Element) sibling;
    sibling = sibling.getNextSibling();
return null;
ElementgetNextSiblingElementNS(Node node, String uri)
get Next Sibling Element NS
Node sibling = node.getNextSibling();
while (sibling != null) {
    if (sibling.getNodeType() == Node.ELEMENT_NODE) {
        String siblingURI = sibling.getNamespaceURI();
        if (siblingURI != null && siblingURI.equals(uri)) {
            return (Element) sibling;
    sibling = sibling.getNextSibling();
return null;
ElementgetNextSiblingElementNS(Node node, String[][] elemNames)
Finds and returns the next sibling node with the given qualified name.
Node sibling = node.getNextSibling();
while (sibling != null) {
    if (sibling.getNodeType() == Node.ELEMENT_NODE) {
        for (int i = 0; i < elemNames.length; i++) {
            String uri = sibling.getNamespaceURI();
            if (uri != null && uri.equals(elemNames[i][0])
                    && sibling.getLocalName().equals(elemNames[i][1])) {
                return (Element) sibling;
...
ElementgetNextVisibleSiblingElement(Node node)
get Next Visible Sibling Element
Node sibling = node.getNextSibling();
while (sibling != null) {
    if (sibling.getNodeType() == Node.ELEMENT_NODE && !isHidden(sibling)) {
        return (Element) sibling;
    sibling = sibling.getNextSibling();
return null;
...
NodegetPreHomoSibling(Node aNode)
get Pre Homo Sibling
Node preSibling = aNode;
while ((preSibling = preSibling.getPreviousSibling()) != null) {
    if (preSibling.getNodeName().equals(aNode.getNodeName())) {
        return preSibling;
return null;
NodegetPreviousSibling(Node node, short nodeType)
get Previous Sibling
Node parent = node.getParentNode();
if (parent == null) {
    System.out.println("Cannot get node [" + node + "] previous sibling. [" + node + "] has no parent.");
    return null;
NodeList siblings = parent.getChildNodes();
int siblingCount = siblings.getLength();
int nodeIndex = 0;
...