Java XML Element Sibling getSiblingNamed(Element element, String name)

Here you can find the source of getSiblingNamed(Element element, String name)

Description

Gets the next sibling to the given element with the given name.

License

LGPL

Return

the next sibling, or null if no such sibling

Declaration


public static Element getSiblingNamed(Element element, String name) 

Method Source Code

//package com.java2s;
// Metawidget (licensed under LGPL)

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /**/*from  ww  w.j  ava2 s. c om*/
     * Gets the next sibling to the given element with the given name.
     *
     * @return the next sibling, or null if no such sibling
     */

    public static Element getSiblingNamed(Element element, String name) {

        if (element == null) {
            return null;
        }

        Node node = element;

        while (true) {
            node = node.getNextSibling();

            if (node == null) {
                return null;
            }

            if (!(node instanceof Element)) {
                continue;
            }

            if (name.equals(node.getLocalName())) {
                return (Element) node;
            }
        }
    }
}

Related

  1. getPreviousSiblingElement(Element elem)
  2. getPreviousSiblingElementByTagName(Element e, String name)
  3. getPrevSibling(Element e)
  4. getPrevSibling(Element element)
  5. getSiblingElement(Element e, String name)