Replacing <nobr> elements in JSoup

Viewed 75

An HTML page can have nested <nobr> elements with or without preceding spaces, e.g.

<p>Paragraph with a <nobr>first element preceded by space</nobr> and a<nobr>second element not preceded by space</nobr>, just by text.</p>

Given this mix, there is no blanket rule for removing <nobr>, because if it is replaced by a leading space it will result in 2 spaces before the first element, whereas if it is not replaced by anything the second element will be joined with the preceding text, yielding ...asecond element..., instead of ...a second element....

Is there any way of doing the replacement of <nobr> in one pass using the Document tree of JSoup, without string processing, so that only 1 space is left in all cases?

0 Answers
Related