/** * Check if an EntityReference node has Text Only child nodes * * @param node * @return true - Contains text only children */ private boolean hasTextOnlyChildren(Node node) { Node child = node; if (child == null) { return false; } child = child.getFirstChild(); while (child != null) { int type = child.getNodeType(); if (type == Node.ENTITY_REFERENCE_NODE) { return hasTextOnlyChildren(child); } else if (type != Node.TEXT_NODE && type != Node.CDATA_SECTION_NODE && type != Node.ENTITY_REFERENCE_NODE) { return false; } child = child.getNextSibling(); } return true; }
|| (prev.getNodeType() == Node.ENTITY_REFERENCE_NODE && hasTextOnlyChildren(prev))) { parent.removeChild(prev); prev = currentNode; || (next.getNodeType() == Node.ENTITY_REFERENCE_NODE && hasTextOnlyChildren(next))) { parent.removeChild(next); next = currentNode;