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 attribute. * * @return the next sibling, or null if no such sibling */ public static Element getSiblingWithAttribute(Element element, String attributeName) { if (element == null) { return null; } Node node = element; while (true) { node = node.getNextSibling(); if (node == null) { return null; } if (!(node instanceof Element)) { continue; } Element nextSibling = (Element) node; if (nextSibling.hasAttribute(attributeName)) { return nextSibling; } } } }