Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { public static boolean hasSameNamedSibling(Node node) { String s = node.getNodeName(); for (Node node1 = node.getPreviousSibling(); node1 != null; node1 = node1.getPreviousSibling()) if (node1.getNodeName().equals(s) && node1.getNodeType() == node.getNodeType()) return true; for (Node node2 = node.getNextSibling(); node2 != null; node2 = node2.getNextSibling()) if (node2.getNodeName().equals(s) && node2.getNodeType() == node.getNodeType()) return true; return false; } }