How would I go about unwrapping an element from its immediate parent if it is an only child. My version of JSoup is 1.6.3 and I cannot upgrade it.
I have tried using the :only-child selector but I don't think this is available in my version of JSoup.
e.g.
<p>
<span>Some text</span>
</p>
should become...
<span>Some text</span>
But...
<div>
<p>Some text</p>
<p>Some more text</p>
</div>
should stay as it is.
Thanks, Michael.
Update:
Desired outcomes...
In the following situation I do want the span to be selected (i.e. where the child element is the only child of its parent):
<p><span>Text</span></p>
In the following situations I do not want the span to be selected (i.e. (1) where the child element is the only child node of its parent but the parent also contains content (2) where the parent element contains more than one child):
<p>Some text <span>continued</span></p>
<p><span>Text</span><a href="#">Link</a></p>
Once I have selected the correct child items I wish to unwrap them from their parent elements. This can be done using the unwrap() method. My main issue is selecting the child elements to unwrap in the first place.