Here you can find the source of hasOnlyTextSiblings(@Nonnull Node node)
public static boolean hasOnlyTextSiblings(@Nonnull Node node)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; import javax.annotation.Nonnull; public class Main { public static boolean hasOnlyTextSiblings(@Nonnull Node node) { Node leftSibling = node.getPreviousSibling(); while (leftSibling != null) { if (!(leftSibling instanceof Text)) { return false; }//w ww . j av a 2 s. co m leftSibling = leftSibling.getPreviousSibling(); } Node rightSibling = node.getNextSibling(); while (rightSibling != null) { if (!(rightSibling instanceof Text)) { return false; } rightSibling = rightSibling.getNextSibling(); } return true; } }