I just want to replace one element with different list of elements, I can't find a way how to do it. Where dynamicContentHtmls
is list of Elements and element
is the one which should be replaced.
My experimental code:
int i=0;
for (Element element: dynamicContents){
//element.remove();
element.append(dynamicContentHtmls.get(i));
//TextNode text = new TextNode(dynamicContentHtmls.get(i), "");
//element.replaceWith(text);
//element.html().replaceAll(element.html(),
//dynamicContentHtmls.get(i));
i++;
}
A HTML element consists of a tag name, attributes, and child nodes (including text nodes and other elements). From an Element, you can extract data, traverse the node graph, and manipulate the HTML.
jsoup can parse HTML files, input streams, URLs, or even strings. It eases data extraction from HTML by offering Document Object Model (DOM) traversal methods and CSS and jQuery-like selectors. jsoup can manipulate the content: the HTML element itself, its attributes, or its text.
A node is the generic name for any type of object in the DOM hierarchy. An element is one specific type of node. The JSoup class model reflects this: Node.
I have solved it by doing this:
element.parent().append(dynamicContentHtmls.get(i));
element.remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With