You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I clone a document, and add an element by the method after(), and try to get the new element by the method nextElementSibling() I get null. In the same time the method nextSibling() successfully returns this element.
If I do the same with the original document everything is fine.
Code:
String html = "<!DOCTYPE html><html lang=\"en\"><head></head><body><div>Initial element</div></body></html>";
Document original = Jsoup.parse(html);
Document clone = original.clone();
Element originalElement = original.body().child(0);
originalElement.after("<div>New element</div>");
Element originalNextElementSibling = originalElement.nextElementSibling();
Element originalNextSibling = (Element) originalElement.nextSibling();
System.out.println("originalNextElementSibling:\n" + originalNextElementSibling);
System.out.println("originalNextSibling:\n" + originalNextSibling);
System.out.println();
Element cloneElement = clone.body().child(0);
cloneElement.after("<div>New element</div>");
Element cloneNextElementSibling = cloneElement.nextElementSibling();
Element cloneNextSibling = (Element) cloneElement.nextSibling();
System.out.println("cloneNextElementSibling:\n" + cloneNextElementSibling);
System.out.println("cloneNextSibling:\n" + cloneNextSibling);
Output:
originalNextElementSibling:
<div>
New element
</div>
originalNextSibling:
<div>
New element
</div>
cloneNextElementSibling:
null
cloneNextSibling:
<div>
New element
</div>
The text was updated successfully, but these errors were encountered:
This commit fix the ISSUE jhy#951
Problem: Once a document is cloned and try to append an after element the document cloned
doesn't recognize the parent and that result in a nextElementSibling equals to null.
Solution: The Element.clone() method calls Element.doClone() with self as parameter to create a new instance.
Changes:
- Element.clone calls to doClone method with self as arg
- New test case added to verify the generated objects are different and with no null values.
"Omar Bautista" <joxebus@gmail.com>
If I clone a document, and add an element by the method
after()
, and try to get the new element by the methodnextElementSibling()
I get null. In the same time the methodnextSibling()
successfully returns this element.If I do the same with the original document everything is fine.
Code:
Output:
The text was updated successfully, but these errors were encountered: