How to replace one item with a list of items using jsoup?

I just want to replace one element with another list of elements, I cannot find a way to do this. Where dynamicContentHtmlsis the list of elements, and elementis the one to 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++;
    }
+4
source share
1 answer

I solved this by doing this:

element.parent().append(dynamicContentHtmls.get(i));
element.remove();
+4
source

All Articles