AbstractHTMLFilter implements HTMLFilter, HTMLConstants { protected void moveChildren(Element parent, Element destination) { NodeList children = parent.getChildNodes(); while (children.getLength() > 0) { destination.appendChild(parent.removeChild(parent.getFirstChild())); } }    }
@Test void moveChildren() { Document document = this.cleaner.clean(new StringReader("<html><body><div><p>test1</p><p>test2</p></div>" + "<span>bla</span></body></html>")); List<Element> divs = htmlFilter.filterDescendants(document.getDocumentElement(), new String[]{ "div" }); assertEquals(1, divs.size()); assertEquals(2, htmlFilter.filterChildren(divs.get(0), "p").size()); List<Element> spans = htmlFilter.filterDescendants(document.getDocumentElement(), new String[]{ "span" }); assertEquals(1, spans.size()); assertTrue(htmlFilter.filterChildren(spans.get(0), "p").isEmpty()); htmlFilter.moveChildren(divs.get(0), spans.get(0)); assertEquals(2, htmlFilter.filterChildren(spans.get(0), "p").size()); assertTrue(htmlFilter.filterChildren(divs.get(0), "p").isEmpty()); }