Java Utililty Methods XML Element Sibling

List of utility methods to do XML Element Sibling

Description

The list of methods to do XML Element Sibling are organized into topic(s).

Method

ElementgetNextSiblingElement(Node node)
Returns the next sibling element of the specified node, or null if there is no such element.
Node sibling = node.getNextSibling();
while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) {
    sibling = sibling.getNextSibling();
return (Element) sibling;
ElementgetNextSiblingElementByTagName(Element e, String name)
Get the next sibling of e which is an element and has tag name name, or null if there is no such element.
Node n = e;
if (n == null)
    return null;
while ((n = n.getNextSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
        return (Element) n;
return null;
...
ElementgetNextSiblingElementWithName(Element elem, String name)
get Next Sibling Element With Name
if (elem == null) {
    return null;
for (Element e = getNextSiblingElement(elem); e != null; e = getNextSiblingElement(e)) {
    if (e.getTagName().equals(name)) {
        return (Element) e;
return null;
Element[]getPrecedingSiblings(Element element, String namespaceUri)
Returns all preceding sibling elements of an element that belong to a certain namespace.
return getPrecedingSiblings(element, namespaceUri, "*");
ElementgetPreviousSiblingElement(Element elem)
get Previous Sibling Element
if (elem == null) {
    return null;
for (Node n = elem.getPreviousSibling(); n != null; n = n.getPreviousSibling()) {
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) n;
return null;
ElementgetPreviousSiblingElementByTagName(Element e, String name)
Get the previous sibling of e which is an element and has tag name name, or null if there is no such element.
Node n = e;
if (n == null)
    return null;
while ((n = n.getPreviousSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
        return (Element) n;
return null;
...
ElementgetPrevSibling(Element e)
get Prev Sibling
Node n = e.getPreviousSibling();
while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
    n = n.getPreviousSibling();
return (Element) n;
ElementgetPrevSibling(Element element)
Get the previous sibling element of the specified element, null if it has no previous other siblings.
if (element == null)
    return null;
Node node = element.getPreviousSibling();
while (node != null) {
    if (node.getNodeType() == Node.ELEMENT_NODE)
        return (Element) node;
    node = node.getPreviousSibling();
return null;
ElementgetSiblingElement(Element e, String name)
Gets the sibling Element with the indicated name.
Element elem = e;
while ((elem = nextSiblingElement(elem)) != null) {
    if (elem.getNodeName().equals(name)) {
        return elem;
return null;
ElementgetSiblingNamed(Element element, String name)
Gets the next sibling to the given element with the given name.
if (element == null) {
    return null;
Node node = element;
while (true) {
    node = node.getNextSibling();
    if (node == null) {
        return null;
...