How can I obtain a Jsoup Element from a String? For example if I have a String
String myDiv = "<div>Hello jsoup world</div>";
that I want to convert in an Element. Currently I convert the String in a Document with the Jsoup.parse(..) method and then I get the body of that document as Element. Is there a direct method?
You can use the XML-Parser instead the HTML one:
final String html = "<div>Hello jsoup world</div>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
Element tag = doc;
Or shorter:
Element tag = Jsoup.parse(html, "", Parser.xmlParser());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With