AbstractHTMLFilter implements HTMLFilter, HTMLConstants { protected void replaceWithChildren(Element element) { Element parent = (Element) element.getParentNode(); while (element.getFirstChild() != null) { parent.insertBefore(element.removeChild(element.getFirstChild()), element); } parent.removeChild(element); }    }
@Test void replaceWithChildren() { Document document = this.cleaner.clean(new StringReader("<html><head><body><div><p>test1</p><p>test2</p></div></body></html>")); List<Element> div = htmlFilter.filterDescendants(document.getDocumentElement(), new String[]{ "div" }); assertEquals(1, div.size()); htmlFilter.replaceWithChildren(div.get(0)); div = htmlFilter.filterDescendants(document.getDocumentElement(), new String[]{ "div" }); assertTrue(div.isEmpty()); List<Element> paragraphs = htmlFilter.filterDescendants(document.getDocumentElement(), new String[]{ "p" }); assertEquals(2, paragraphs.size()); }