Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.*; public class Main { public static boolean hasOnlyTextSiblings(/*@Nonnull*/Node node) { Node leftSibling = node.getPreviousSibling(); while (leftSibling != null) { if (!(leftSibling instanceof Text)) { return false; } leftSibling = leftSibling.getPreviousSibling(); } Node rightSibling = node.getNextSibling(); while (rightSibling != null) { if (!(rightSibling instanceof Text)) { return false; } rightSibling = rightSibling.getNextSibling(); } return true; } }