Skip to content Skip to sidebar Skip to footer

How I Can Replace "text" In The Each Tag Using Jsoup

I have the following html:

text text text

Solution 1:

Document doc = Jsoup.connect(url).get();
Stringstr = doc.toString();
str = str.replace("text", "word");

try it..

Solution 2:

A quick search turned up this code:

Elementsstrongs= doc.select("strong");
Elementf= strongs.first();
Elementl= strongs.last();1,siblings.lastIndexOf(l));

etc

First what you want to do is understand how the library works and what features it contains, and then you figure out how to use the library to do what you need. The code above seems to allow you to select a strong element, at which point you could update it's inner text, but I'm sure there are a number of ways you could accomplish the same.

In general, most libraries which parse xml are able to select any given element in the document object model, or any list of elements, and either manipulate the elements themselves, or their inner text, attributes and the like.

Once you gain more experience working with different libraries, your starting point is to look for the documentation of the library to see what that library does. If you see a method that says it does something, that's what it does, and you can expect to use it to accomplish that goal. Then, instead of writing a question on Stack Overflow, you just need to parse the functionality of the library you're using, and figure out how to use it to do what you want.

Post a Comment for "How I Can Replace "text" In The Each Tag Using Jsoup"