Java tutorial
//package com.java2s; // License as published by the Free Software Foundation; either import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * 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.getNodeName())) { return (Element) node; } } } }