AbstractHTMLFilter implements HTMLFilter, HTMLConstants { protected List<Element> filterChildren(Element parent, String tagName) { List<Element> result = new ArrayList<>(); Node current = parent.getFirstChild(); while (current != null) { if (current.getNodeName().equals(tagName)) { result.add((Element) current); } current = current.getNextSibling(); } return result; }    }
@Test void filterChildren() { Document document = this.cleaner.clean(new StringReader("<html><head><body><p>test1</p><p>test2</p></body></html>")); List<Element> body = htmlFilter.filterChildren(document.getDocumentElement(), "body"); assertEquals(1, body.size()); List<Element> paragraphs = htmlFilter.filterChildren(body.get(0), "p"); assertEquals(2, paragraphs.size()); assertEquals("test1", paragraphs.get(0).getTextContent()); assertEquals("test2", paragraphs.get(1).getTextContent()); }