private static boolean isWhitespace(String text) { if (text == null) return true; boolean isWhitespace = true; for (int i = text.length() - 1; i >= 0; i--) { char ch = text.charAt(i); if (!Character.isWhitespace(ch)) { // check for comment if (ch == '>' && text.indexOf("-->") + 2 == i) { int head = text.indexOf("<!--"); if (head >= 0) { for (int j = 0; j < head; j++) { if (!Character.isWhitespace(text.charAt(j))) { return false; } } return true; } } return false; } } return true; }