Skip to content

Commit 6d24910

Browse files
committed
Document last-child selector limitations in StreamParser
Resolves #2437
1 parent 5340d4b commit 6d24910

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/org/jsoup/parser/StreamParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ Iterator interface. Elements returned will be complete with all their children,
4747
stream consumers will throw an {@link java.io.UncheckedIOException} if the underlying Reader errors during read.</p>
4848
<p>For examples, see the jsoup
4949
<a href="https://jsoup.org/cookbook/input/streamparser-dom-sax">StreamParser cookbook.</a></p>
50-
@since 1.18.1
51-
*/
50+
<p>
51+
Selectors that depend on knowing all siblings (e.g. {@code :last-child}, {@code :last-of-type}, {@code :nth-last-child},
52+
{@code :only-child} and their negations) cannot be correctly evaluated while streaming, because the parser does not know
53+
if a later sibling will appear. For those cases, run {@link #complete()} first to finish the parse (which is effectively
54+
the same as using {@code Jsoup.parse(...)} unless you have already removed nodes during streaming).
55+
</p>
56+
@since 1.18.1 */
5257
public class StreamParser implements Closeable {
5358
final private Parser parser;
5459
final private TreeBuilder treeBuilder;

0 commit comments

Comments
 (0)