There is a code for parsing and making some changes to the displayed text:
Document doc; try { doc = Jsoup.connect(contentUrl).get(); imagesRec = doc.select("div.post-featured-img amp-img[src~=(?i)\\.(png|jpe?g|gif)]"); imgSrcUrl = imagesRec.attr("abs:src"); contentPrepared = new StringBuilder(); for (Element p : doc.select("div.amp-wp-article-content p, div.amp-wp-article-content h2, div.amp-wp-article-content h3, div.amp-wp-article-content cite")) { contentPrepared.append(p.text()); contentPrepared.append("\n" + "\n"); } for (Element p : doc.select("div.amp-wp-article-content li")) { contentPrepared.append(p.text()); contentPrepared.append("-----"); } contentFinal = contentPrepared.toString(); As the code shows, I want to take the classes div.amp-wp-article-content p , div.amp-wp-article-content h2 , div.amp-wp-article-content h3 and div.amp-wp-article-content cite and insert new lines between them, and it works great.
The whole problem is in the second "insert", more precisely in the final form of the text. I want to take the class div.amp-wp-article-content li and insert "-----" before it. All this works, but when displaying, the contents of the tags from the first StringBuilder first StringBuilder , and then, at the end of the page, the contents of the tags from the second StringBuilder .
Question: how to display elements in the order in which they should be on the page? Those. The text inside the div.amp-wp-article-content li tag should not be located at the bottom of the page, but between the tags from the first StrinBuilder.
selectand inside the loop, make a check of the element: if it isli- add"-----", if not -"\n\n"- woesss