Is there a way to deep clone JSoup Document object and get back exactly same HTML?
I have a pre-parsed object that I want to just clone because I suspect that clone would be faster than always parsing the HTML again.
I've tried to clone it by just iterating through of all the elements of the Document object, but then I'm left without the doctype declaration and such.
P.S. I don't of course expect to get the comments...
For any Node you can call .clone()
This was implemented in feature request.
As I was confused by the answer and OP's comment on it, here is the result of my humble research :-).
document.clone()
produces a deep copy of the document object and all of its children. It is true according to documentation and my own experiments.
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